Exemple #1
0
        public String SaveDocument(DB.SYS_DOC_Header entity, long printer)
        {
            String message = "";

            try
            {
                long?defaultSiteId = BL.ApplicationDataContext.Instance.LoggedInUser.DefaultSiteId;
                //Clear the document number as it is only assigned if equal to NULL or -1
                entity.DocumentNumber = null;
                BL.ApplicationDataContext.Instance.LoggedInUser             = (DB.SEC_User)BL.SEC.SEC_User.LoadByPerson(entity.CreatedBy.Value, DataContext);
                BL.ApplicationDataContext.Instance.LoggedInUser.DefaultSite = BL.ApplicationDataContext.Instance.SystemEntityContext.SYS_Site.Include("SYS_Entity").FirstOrDefault(n => n.EntityId == defaultSiteId);
                BL.ApplicationDataContext.Instance.PopulateModuleAccess();
                BL.ApplicationDataContext.Instance.PopulateValidationRestrictions();
                BL.EntityController.SaveSYS_DOC_Header(entity, DataContext);
                //TODO : Need to check if this works
                entity   = DataContext.EntitySystemContext.SYS_DOC_Header.FirstOrDefault(n => n.Id == entity.Id);
                message += String.Format("Success,{0},{1}", entity?.DocumentNumber, entity?.TrackId);
                if (printer != 0)
                {
                    RegisterPrintJob(entity.Id, printer);
                }
            }
            catch (Exception ex)
            {
                message = "Exception : " + ex.ToString();
            }
            return(message);
        }
Exemple #2
0
        /// <summary>
        /// Creates Goods Received from Purchase Order
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static DB.SYS_DOC_Header CreateGoodsReceivedFromPurchaseOrder(DB.SYS_DOC_Header entity, DataContext dataContext)
        {
            DB.SYS_DOC_Header docHeader = CopyDocument(entity, dataContext);
            docHeader.PurchaseOrder = CopyDocument(entity, dataContext);
            //Is already set not sure why I did it
            //docHeader.PurchaseOrder.TypeId = (byte)SYS.SYS_DOC_Type.PurchaseOrder;
            docHeader.TypeId = (byte)SYS.SYS_DOC_Type.GoodsReceived;

            //Remove lines that you have no received items for
            List <DB.SYS_DOC_Line> removeLines = new List <DB.SYS_DOC_Line>();

            Parallel.ForEach(docHeader.SYS_DOC_Line.Where(n => (n.LineItem.TypeId == (byte)SYS.SYS_Type.Account && n.Amount == n.AmountInvoiced) ||
                                                          (n.LineItem.TypeId == (byte)SYS.SYS_Type.Inventory && n.QtyOutstanding == 0)),
                             line =>
            {
                removeLines.Add(line);
            });
            removeLines.ForEach(n => docHeader.SYS_DOC_Line.Remove(n));

            Parallel.ForEach(docHeader.SYS_DOC_Line, line => {
                line.Quantity = line.QtyOutstanding;
                if (line.LineItem.TypeId == (byte)SYS.SYS_Type.Account)
                {
                    line.Amount = line.Amount - line.AmountInvoiced;
                }
            });

            docHeader.Generated = true;
            return(docHeader);
        }
Exemple #3
0
        protected override bool SaveSuccessful()
        {
            try
            {
                DialogResult result = Essential.BaseAlert.ShowAlert("Save Document", "You are about the save this document do you wish to continue ?", Essential.BaseAlert.Buttons.OkCancel, Essential.BaseAlert.Icons.Information);
                using (new CDS.Client.Desktop.Essential.UTL.WaitCursor())
                {
                    this.OnSaveRecord();

                    Int64 printerId = 0;
                    switch (result)
                    {
                    case System.Windows.Forms.DialogResult.Yes:
                        printerId = BL.ApplicationDataContext.Instance.LoggedInUser.DefaultPrinterId.Value;
                        break;

                    case System.Windows.Forms.DialogResult.No:
                        printerId = 0;
                        break;

                    case System.Windows.Forms.DialogResult.Cancel:
                        printerId = -1;
                        return(false);
                    }

                    DB.SYS_DOC_Header entry = ((DB.SYS_DOC_Header)BindingSourceDocument.DataSource);
                    entry.ITM_BOM_Document = ((DB.ITM_BOM_Document)BindingSource.DataSource);
                    //Add result item
                    DB.SYS_DOC_Line resultLine = BL.SYS.SYS_DOC_Line.New;
                    resultLine.ItemId = ((DB.ITM_BOM_Recipe)BindingSourceRecipe.DataSource).ItemResultId;
                    DB.ITM_History itm_history = BL.ITM.ITM_History.GetItemCurrentHistory(DataContext.EntityInventoryContext.ITM_Inventory.FirstOrDefault(n => n.EntityId == resultLine.ItemId), DataContext);
                    resultLine.Quantity    = ((DB.ITM_BOM_Recipe)BindingSourceRecipe.DataSource).QuantityResult * (entry.TypeId == (byte)BL.SYS.SYS_DOC_Type.BOMAssemblyStarted ? 1 : -1);
                    resultLine.Description = DataContext.ReadonlyContext.VW_LineItem.FirstOrDefault(n => n.Id == resultLine.ItemId).Description;
                    resultLine.Amount      = itm_history.UnitAverage;
                    resultLine.Total       = resultLine.Quantity * resultLine.Amount;
                    resultLine.TotalTax    = 0;
                    //SYS DOC Lines
                    sys_doc_line.Add(resultLine);
                    sys_doc_line.ForEach(n => n.LineItem = DataContext.ReadonlyContext.VW_LineItem.FirstOrDefault(k => k.Id == n.ItemId));
                    BL.ApplicationDataContext.Instance.Service.SaveDocument(entry, printerId);
                    btnComplete.Visibility = DevExpress.XtraBars.BarItemVisibility.Always;
                    btnCancel.Visibility   = DevExpress.XtraBars.BarItemVisibility.Always;

                    return(true);

                    //If you ever remove this make sure that you refresh all the datasources as the BindingSource.DataSource is save disjoint from the DataContext
                    ForceClose = true;
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                if (CDS.Shared.Exception.UserInterfaceExceptionHandler.HandleException(ref ex))
                {
                    throw ex;
                }
                return(false);
            }
        }
Exemple #4
0
 public override void OpenRecord(long Id)
 {
     base.OpenRecord(Id);
     Doc_Header = BL.SYS.SYS_DOC_Header.Load(Id, DataContext, new List <String>()
     {
         "SYS_DOC_Line"
     });
 }
Exemple #5
0
 /// <summary>
 /// Calling this method automatically opens the indicated form as a Mdi child form in the main form tabs.
 /// Exposes a way to open the Jobs Form from a Project outside of CDS.Client.Desktop.Workshop
 /// </summary>
 /// <param name="form">The form control to be displayed in the tabs.</param>
 /// <remarks>Created: Werner Scheffer 27/10/2014</remarks>
 public void ShowJobFormFromHeader(DB.SYS_DOC_Header header, bool allowChanges)
 {
     CDS.Client.Desktop.Workshop.Job.JobForm childForm = new Workshop.Job.JobForm();
     childForm.Doc_Header = header;
     childForm.Job_header = header.JOB_Header;
     childForm.ItemState  = CDS.Client.Desktop.Essential.BaseForm.EntityState.Generated;
     ShowForm(childForm);
 }
Exemple #6
0
        /// <summary>
        /// Call this method to open a New Generated document.
        /// </summary>
        /// <param name="header">Newly generated SYS_DOC_Header of document you are opening.</param>
        /// <remarks>Created: Henko Rabie 29/01/2015</remarks>
        public void ShowDocumentForm(DB.SYS_DOC_Header header)
        {
            var        mainform    = Application.OpenForms["MainForm"];
            Type       typExternal = mainform.GetType();
            MethodInfo methodInf   = typExternal.GetMethod("ShowDocumentFormFromHeader");

            methodInf.Invoke(mainform, new object[] { header });
        }
Exemple #7
0
 protected override void OnStart()
 {
     base.OnStart();
     Doc_Header = BL.SYS.SYS_DOC_Document.New(BL.SYS.SYS_DOC_Type.InventoryAdjustment);
     BindingSource.DataSource      = Doc_Header;
     BindingSourceLines.DataSource = lines;
     //When the form opens we populate it the the current items required fields
     AddLine(entityId);
 }
Exemple #8
0
        /// <summary>
        /// Returns a new blank document should only be used for the copy document method
        /// </summary>
        /// <param name="TypeId">Document Type Id</param>
        /// <returns>The will return a new document of the type specified</returns>
        public static DB.SYS_DOC_Header New(SYS_DOC_Type type)
        {
            DB.SYS_DOC_Header document = SYS_DOC_Header.New;
            document.TypeId = (byte)type;
            //Tried to do this here but the server cant save for some reason
            //document.SYS_Tracking = SYS.SYS_Tracking.New;
            //document.ORG_TRX_Header.Add(BL.ORG.ORG_TRX_Header.New);

            return(document);
        }
Exemple #9
0
 public override void Recover(List <BindingSource> bindingSources)
 {
     base.Recover(bindingSources);
     Doc_Header = (BindingSource.DataSource as DB.SYS_DOC_Header);
     if (lines.Any())
     {
         grvItems.OptionsBehavior.Editable = true;
     }
     ItemState = EntityState.Recovered;
 }
Exemple #10
0
        /// <summary>
        /// Creates Job from Quote
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static DB.SYS_DOC_Header CreateJobFromJobQuote(DB.SYS_DOC_Header entity, DataContext dataContext)
        {
            DB.SYS_DOC_Header docHeader = CopyDocument(entity, dataContext);
            docHeader.TypeId     = (byte)SYS.SYS_DOC_Type.Job;
            docHeader.JOB_Header = JOB.JOB_Header.New;

            docHeader.JOB_Header.CompanyId            = docHeader.ORG_TRX_Header.CompanyId;
            docHeader.JOB_Header.Telephone            = docHeader.ORG_TRX_Header.Telephone;
            docHeader.JOB_Header.ContactPerson        = docHeader.ORG_TRX_Header.ContactPerson;
            docHeader.JOB_Header.ContactTelephone     = docHeader.ORG_TRX_Header.ContactTelephone;
            docHeader.JOB_Header.ReferenceShort1      = docHeader.ORG_TRX_Header.ReferenceShort1;
            docHeader.JOB_Header.ReferenceShort2      = docHeader.ORG_TRX_Header.ReferenceShort2;
            docHeader.JOB_Header.ReferenceShort3      = docHeader.ORG_TRX_Header.ReferenceShort3;
            docHeader.JOB_Header.ReferenceShort4      = docHeader.ORG_TRX_Header.ReferenceShort4;
            docHeader.JOB_Header.ReferenceShort5      = docHeader.ORG_TRX_Header.ReferenceShort5;
            docHeader.JOB_Header.ReferenceLong1       = docHeader.ORG_TRX_Header.ReferenceLong1;
            docHeader.JOB_Header.ReferenceLong2       = docHeader.ORG_TRX_Header.ReferenceLong2;
            docHeader.JOB_Header.ReferenceLong3       = docHeader.ORG_TRX_Header.ReferenceLong3;
            docHeader.JOB_Header.ReferenceLong4       = docHeader.ORG_TRX_Header.ReferenceLong4;
            docHeader.JOB_Header.ReferenceLong5       = docHeader.ORG_TRX_Header.ReferenceLong5;
            docHeader.JOB_Header.ShippingAddressLine1 = docHeader.ORG_TRX_Header.ShippingAddressLine1;
            docHeader.JOB_Header.ShippingAddressLine2 = docHeader.ORG_TRX_Header.ShippingAddressLine2;
            docHeader.JOB_Header.ShippingAddressLine3 = docHeader.ORG_TRX_Header.ShippingAddressLine3;
            docHeader.JOB_Header.ShippingAddressLine4 = docHeader.ORG_TRX_Header.ShippingAddressLine4;
            docHeader.JOB_Header.ShippingAddressCode  = docHeader.ORG_TRX_Header.ShippingAddressCode;
            docHeader.JOB_Header.BillingAddressLine1  = docHeader.ORG_TRX_Header.BillingAddressLine1;
            docHeader.JOB_Header.BillingAddressLine2  = docHeader.ORG_TRX_Header.BillingAddressLine2;
            docHeader.JOB_Header.BillingAddressLine3  = docHeader.ORG_TRX_Header.BillingAddressLine3;
            docHeader.JOB_Header.BillingAddressLine4  = docHeader.ORG_TRX_Header.BillingAddressLine4;
            docHeader.JOB_Header.BillingAddressCode   = docHeader.ORG_TRX_Header.BillingAddressCode;
            docHeader.JOB_Header.Date1 = null;
            docHeader.JOB_Header.Date2 = null;
            docHeader.JOB_Header.Date3 = null;

            foreach (DB.SYS_DOC_Line line in docHeader.SYS_DOC_Line)
            {
                switch (line.LineItem.TypeId)
                {
                case (byte)SYS.SYS_Type.Account:
                    break;

                case (byte)SYS.SYS_Type.Inventory:
                case (byte)SYS.SYS_Type.BuyOut:
                    line.Quantity = Math.Min(line.Quantity, line.LineItem.OnHand);
                    line.Amount   = line.LineItem.UnitAverage;
                    line.Total    = line.Quantity * line.Amount;
                    line.TotalTax = 0;
                    break;
                }
            }

            return(docHeader);
        }
Exemple #11
0
        private void btnCancel_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {
                DialogResult result = Essential.BaseAlert.ShowAlert("Cancel Document", "You are about the cancel this document do you wish to continue ?", Essential.BaseAlert.Buttons.OkCancel, Essential.BaseAlert.Icons.Information);

                Int64 printerId = 0;
                switch (result)
                {
                case System.Windows.Forms.DialogResult.Yes:
                    printerId = BL.ApplicationDataContext.Instance.LoggedInUser.DefaultPrinterId.Value;
                    break;

                case System.Windows.Forms.DialogResult.No:
                    printerId = 0;
                    break;

                case System.Windows.Forms.DialogResult.Cancel:
                    printerId = -1;
                    break;
                }

                DB.SYS_DOC_Header sys_doc_header = BL.SYS.SYS_DOC_Document.New(BL.SYS.SYS_DOC_Type.BOMCanceled);
                //DB.ITM_BOM_Document itm_bom_document = ((DB.ITM_BOM_Document)BindingSource.DataSource);//DataContext.EntityInventoryContext.ITM_BOM_Document.FirstOrDefault(n => n.HeaderId == sys_doc_header.Id); //sys_doc_header.ITM_BOM_Document.FirstOrDefault();
                foreach (DB.SYS_DOC_Line line in ((DB.SYS_DOC_Header)BindingSourceDocument.DataSource).SYS_DOC_Line)
                {
                    sys_doc_header.SYS_DOC_Line.Add(BL.ApplicationDataContext.DeepClone(line, BL.SYS.SYS_DOC_Line.New));
                }
                sys_doc_header.BOMDocumentId = ((DB.ITM_BOM_Document)BindingSource.DataSource).Id;
                //Werner: This was moved to the DataService
                //itm_bom_document.RecipeId = ((DB.ITM_BOM_Recipe)BindingSourceRecipe.DataSource).Id;
                //itm_bom_document.ItemResultId = ((DB.ITM_BOM_Recipe)BindingSourceRecipe.DataSource).ItemResultId;
                //itm_bom_document.QuantityExpectedResult = ((DB.ITM_BOM_Recipe)BindingSourceRecipe.DataSource).QuantityResult;
                //itm_bom_document.QuantityActualResult = 0;
                //itm_bom_document.CancelParent = ((DB.ITM_BOM_Document)BindingSource.DataSource).Id;

                BL.ApplicationDataContext.Instance.Service.SaveDocument(sys_doc_header, printerId);

                //If you ever remove this make sure that you refresh all the datasources as the BindingSource.DataSource is save disjoint from the DataContext
                ForceClose = true;
                this.Close();
            }
            catch (Exception ex)
            {
                if (CDS.Shared.Exception.UserInterfaceExceptionHandler.HandleException(ref ex))
                {
                    throw ex;
                }
            }
        }
Exemple #12
0
        public override void OpenRecord(long Id)
        {
            base.OpenRecord(Id);
            IsSaved = true;

            Doc_Header = BL.SYS.SYS_DOC_Header.Load(Id, DataContext, new List <String>()
            {
                "SYS_DOC_Line"
            });
            Job_header = BL.JOB.JOB_Header.LoadByHeaderId(Id, DataContext);

            //Must disable company dropdown user not allowed to change company
            ddlCompany.Properties.ReadOnly = true;
        }
Exemple #13
0
        private void btnSalesOrder_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (!ValidateBeforeSave())
            {
                return;
            }

            if (SaveSuccessful())
            {
                IgnoreChanges = true;
                DB.SYS_DOC_Header salesorder = BL.SYS.DocumentProcessor.CreateSalesOrderFromJob(Doc_Header, DataContext);
                this.Close();
                ShowDocumentForm(salesorder);
            }
        }
Exemple #14
0
        internal static String Save(DB.SYS_DOC_Header entry, DataContext dataContext)
        {
            try
            {
                if (dataContext.EntitySystemContext.GetEntityState(entry) == System.Data.Entity.EntityState.Detached)
                {
                    dataContext.EntitySystemContext.SYS_DOC_Header.Add(entry);
                }
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException)
            {
                return(dataContext.PackageValidationException());
            }

            return("Success");
        }
Exemple #15
0
        private static DB.SYS_DOC_Header CopyDocument(DB.SYS_DOC_Header entity, DataContext dataContext)
        {
            DB.SYS_DOC_Header docHeader = ApplicationDataContext.DeepClone <DB.SYS_DOC_Header>(entity, SYS.SYS_DOC_Document.New(SYS.SYS_DOC_Type.Quote));
            docHeader.DocumentNumber = null;
            DB.ORG_TRX_Header trxHeader = null;
            if (entity.ORG_TRX_Header != null)
            {
                trxHeader = ApplicationDataContext.DeepClone <DB.ORG_TRX_Header>(entity.ORG_TRX_Header, ORG.ORG_TRX_Header.New);
            }
            DB.JOB_Header jobHeader = null;
            if (entity.JOB_Header != null)
            {
                jobHeader = ApplicationDataContext.DeepClone <DB.JOB_Header>(entity.JOB_Header, JOB.JOB_Header.New);
            }

            foreach (DB.SYS_DOC_Line line in entity.SYS_DOC_Line)
            {
                DB.SYS_DOC_Line newLine = ApplicationDataContext.DeepClone <DB.SYS_DOC_Line>(line, SYS.SYS_DOC_Line.New);

                //Werner: Wanted to do this here but some of the document needs these values to generate another document
                ////Need to clear these when copying a documents lines
                //newLine.QtyReceived = 0;
                //newLine.QtyOutstanding = 0;
                //TODO : Just check but this should always be null as the DeepCopy
                //ignores all DB.* types
                if (line.LineItem != null)
                {
                    newLine.LineItem = line.LineItem;
                }
                else
                {
                    if (!dataContext.ReadonlyContext.VW_LineItem.Any(n => n.Id == newLine.ItemId && n.TypeId == (byte)SYS.SYS_Type.Account))
                    {
                        newLine.LineItem    = dataContext.ReadonlyContext.VW_LineItem.FirstOrDefault(n => n.Id == newLine.ItemId);
                        newLine.UnitAverage = newLine.LineItem.UnitAverage;
                        newLine.UnitCost    = newLine.LineItem.UnitCost;
                    }
                }

                docHeader.SYS_DOC_Line.Add(newLine);
            }

            docHeader.ORG_TRX_Header = trxHeader;
            docHeader.JOB_Header     = jobHeader;

            return(docHeader);
        }
Exemple #16
0
        public String PrintDocument(DB.SYS_DOC_Header entity, long printer)
        {
            String message = "";

            try
            {
                BL.ApplicationDataContext.Instance.LoggedInUser = (DB.SEC_User)BL.SEC.SEC_User.LoadByPerson(entity.CreatedBy.Value, DataContext);
                BL.ApplicationDataContext.Instance.PopulateModuleAccess();
                BL.ApplicationDataContext.Instance.PopulateValidationRestrictions();
                message += String.Format("Success,{0},{1}", entity.DocumentNumber, entity.TrackId);
                if (printer != 0)
                {
                    RegisterPrintJob(entity.Id, printer);
                }
            }
            catch (Exception ex)
            {
                message = "Exception : " + ex.ToString();
            }
            return(message);
        }
Exemple #17
0
        /// <summary>
        /// Only for use when saving a Sales Order
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static DB.SYS_DOC_Header CreateTaxInvoiceFromSalesOrder(DB.SYS_DOC_Header entity, DataContext dataContext)
        {
            DB.SYS_DOC_Header docHeader = CopyDocument(entity, dataContext);

            docHeader.TypeId     = (byte)SYS.SYS_DOC_Type.TAXInvoice;
            docHeader.SalesOrder = entity;

            foreach (DB.SYS_DOC_Line line in docHeader.SYS_DOC_Line)
            {
                //Need to do this as total needs to change if only partially invoiced
                line.Quantity = line.Quantity - line.QtyOutstanding;
                line.Total    = Math.Round(line.Amount * (line.LineItem.TypeId == (byte)SYS.SYS_Type.Account ? 1 : line.Quantity), 2, MidpointRounding.AwayFromZero);
                // Henko - TODO: Check if Tax should be added for this company - no access to company....
                line.TotalTax = line.Total * ApplicationDataContext.Instance.CompanySite.VatPercentage / 100;
            }

            //if (SECL.SecurityLibrary.AccessGranted(SECL.AccessCodes.SADOBORECR))
            //    docHeader.BackOrder = CreateBackOrderFromSalesOrder(entity, dataContext);

            return(docHeader);
        }
Exemple #18
0
        /// <summary>
        /// Creates a Sales Order from Back Order
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static DB.SYS_DOC_Header CreateSalesOrderFromBackOrder(DB.SYS_DOC_Header entity, DataContext dataContext)
        {
            DB.SYS_DOC_Header docHeader = CopyDocument(entity, dataContext);

            docHeader.TypeId    = (byte)SYS.SYS_DOC_Type.SalesOrder;
            docHeader.BackOrder = CopyDocument(entity, dataContext);
            foreach (DB.SYS_DOC_Line line in docHeader.SYS_DOC_Line)
            {
                if (line.QtyOutstanding > line.LineItem.OnHand)
                {
                    line.Quantity = line.LineItem.OnHand;
                }
                else
                {
                    line.Quantity = line.QtyOutstanding;
                }
                line.QtyOutstanding = line.QtyReceived = 0;
            }
            docHeader.Generated = true;
            return(docHeader);
        }
Exemple #19
0
        private void btnCreateJob_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            using (new CDS.Client.Desktop.Essential.UTL.WaitCursor())
            {
                if (DataContext.EntitySystemContext.GetEntityState(Doc_Header) == System.Data.Entity.EntityState.Detached)
                {   //Need to save Job Quote before converting
                    OnSaveRecord();
                }

                DB.SYS_DOC_Header job = BL.SYS.DocumentProcessor.CreateJobFromJobQuote(Doc_Header, DataContext);

                IgnoreChanges = true;
                this.Close();

                var  mainform    = Application.OpenForms["MainForm"];
                Type typExternal = mainform.GetType();
                System.Reflection.MethodInfo methodInf = typExternal.GetMethod("ShowJobFormFromHeader");

                methodInf.Invoke(mainform, new object[] { job, true });
            }
        }
Exemple #20
0
        /// <summary>
        /// Cancel a document.
        /// Purchase Order: ???
        /// Credit Note: ???
        /// </summary>
        /// <param name="entityId">SYS_DOC_Header Id of document to be approved</param>
        /// <param name="personId">SYS_Person Id of user approving document</param>
        /// <returns>Success message on success.
        /// Exception message on exception
        /// </returns>
        public String RejectDocument(long entityId, long personId)
        {
            String message = "";

            try
            {
                BL.ApplicationDataContext.Instance.LoggedInUser = (DB.SEC_User)BL.SEC.SEC_User.LoadByPerson(personId, DataContext);
                BL.ApplicationDataContext.Instance.PopulateModuleAccess();
                BL.ApplicationDataContext.Instance.PopulateValidationRestrictions();
                DB.SYS_DOC_Header entity = BL.SYS.SYS_DOC_Header.Load(entityId, DataContext, new List <string> {
                    "SYS_DOC_Line"
                });
                entity.ORG_TRX_Header = BL.ORG.ORG_TRX_Header.LoadByHeaderId(entityId, DataContext);
                BL.EntityController.RejectSYS_DOC_Header(entity, DataContext);
                message += String.Format("Success,{0},{1}", entity.DocumentNumber, entity.TrackId);
            }
            catch (Exception ex)
            {
                message = "Exception : " + ex.ToString();
            }
            return(message);
        }
Exemple #21
0
        /// <summary>
        /// Creates a Purchase Order from Back Order
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static DB.SYS_DOC_Header CreatePurchaseOrderFromBackOrder(DB.SYS_DOC_Header entity, DataContext dataContext)
        {
            DB.SYS_DOC_Header docHeader = CopyDocument(entity, dataContext);
            //Need to clear SelectedCompany
            docHeader.ORG_TRX_Header.CompanyId = 0;
            docHeader.TypeId = (byte)SYS.SYS_DOC_Type.PurchaseOrder;
            foreach (DB.SYS_DOC_Line line in docHeader.SYS_DOC_Line)
            {
                line.QtyOutstanding = line.QtyReceived = 0;
                switch (line.LineItem.TypeId)
                {
                case (byte)SYS.SYS_Type.Inventory:
                    line.Amount = line.LineItem.UnitCost;
                    break;

                case (byte)SYS.SYS_Type.Account:
                    line.Amount = line.Amount - line.AmountInvoiced;
                    break;
                }
            }
            docHeader.Generated = true;
            return(docHeader);
        }
Exemple #22
0
        /// <summary>
        /// For use in this class only
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static DB.SYS_DOC_Header CreateBackOrderFromSalesOrder(DB.SYS_DOC_Header entity, DataContext dataContext)
        {
            //If there is no BackOrder quantities return null
            if (!entity.SYS_DOC_Line.Any(n => n.QtyOutstanding != 0))
            {
                return(null);
            }

            DB.SYS_DOC_Header docHeader = CopyDocument(entity, dataContext);

            docHeader.TypeId     = (byte)SYS.SYS_DOC_Type.BackOrder;
            docHeader.SalesOrder = entity;
            docHeader.SiteId     = Convert.ToInt64(ApplicationDataContext.Instance.LoggedInUser.DefaultSiteId);
            foreach (DB.SYS_DOC_Line line in docHeader.SYS_DOC_Line)
            {
                line.Quantity = line.QtyOutstanding;
                line.Total    = Math.Round(line.Amount * (line.LineItem.TypeId == (byte)SYS.SYS_Type.Account ? 1 : line.Quantity), 2, MidpointRounding.AwayFromZero);
                // Henko - TODO: Check if Tax should be added for this company - no access to company....
                line.TotalTax = line.Total * ApplicationDataContext.Instance.CompanySite.VatPercentage / 100;
            }
            docHeader.Generated = true;
            return(docHeader);
        }
Exemple #23
0
        /// <summary>
        /// Creates a Sales Credit Note from TAX Invoice
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static DB.SYS_DOC_Header CreateCreditNoteFromTAXInvoice(DB.SYS_DOC_Header entity, DataContext dataContext)
        {
            DB.SYS_DOC_Header docHeader = CopyDocument(entity, dataContext);

            docHeader.TypeId     = (byte)SYS.SYS_DOC_Type.CreditNote;
            docHeader.TaxInvoice = CopyDocument(entity, dataContext);
            //Remove lines that you have no received items for
            List <DB.SYS_DOC_Line> removeLines = new List <DB.SYS_DOC_Line>();

            Parallel.ForEach(docHeader.SYS_DOC_Line.Where(n => (n.LineItem.TypeId == (byte)SYS.SYS_Type.Account && n.Amount == n.AmountCredited) ||
                                                          (n.LineItem.TypeId == (byte)SYS.SYS_Type.Inventory && n.QtyReceived == 0)),
                             line =>
            {
                removeLines.Add(line);
            });

            removeLines.ForEach(n => docHeader.SYS_DOC_Line.Remove(n));

            //Populate Quantity on Goods Returned for returnable items
            Parallel.ForEach(docHeader.SYS_DOC_Line.Where(n => (n.LineItem.TypeId == (byte)SYS.SYS_Type.Account && n.Amount != n.AmountCredited) ||
                                                          (n.LineItem.TypeId == (byte)SYS.SYS_Type.Inventory && n.QtyReceived != 0)),
                             line =>
            {
                switch (line.LineItem.TypeId)
                {
                case (byte)SYS.SYS_Type.Account:
                    line.Amount = line.Amount - line.AmountCredited;
                    break;

                case (byte)SYS.SYS_Type.Inventory:
                    line.Quantity = line.QtyReceived;
                    break;
                }
            });
            docHeader.Generated = true;
            return(docHeader);
        }
Exemple #24
0
        /// <summary>
        /// Creates a Sales Order from Quote
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static DB.SYS_DOC_Header CreateSalesOrderFromQuote(DB.SYS_DOC_Header entity, DataContext dataContext)
        {
            DB.SYS_DOC_Header docHeader = CopyDocument(entity, dataContext);

            docHeader.TypeId = (byte)SYS.SYS_DOC_Type.SalesOrder;
            docHeader.Quote  = entity;
            foreach (DB.SYS_DOC_Line line in docHeader.SYS_DOC_Line)
            {
                line.QtyOutstanding = line.QtyReceived = 0;
                if (line.Quantity > line.LineItem.OnHand)
                {
                    if (!SECL.SecurityLibrary.AccessGranted(SECL.AccessCodes.SADOBORECR))
                    {
                        line.Quantity = line.LineItem.OnHand;
                    }
                    else if (SECL.SecurityLibrary.AccessGranted(SECL.AccessCodes.SADOBORECR))
                    {
                        line.QtyOutstanding = line.Quantity - line.LineItem.OnHand;
                    }
                }
            }
            docHeader.Generated = true;
            return(docHeader);
        }
Exemple #25
0
        private DB.SYS_DOC_Header GenerateStockTakeDocument()
        {
            DB.SYS_DOC_Header sys_header = BL.SYS.SYS_DOC_Document.New(BL.SYS.SYS_DOC_Type.InventoryAdjustment);
            sys_header.ORG_TRX_Header = BL.ORG.ORG_TRX_Header.New;
            sys_header.ORG_TRX_Header.ReferenceLong2 = ((DB.ITM_StockTake)BindingSource.DataSource).Description;

            foreach (DB.ITM_StockTakeItem item in ((DB.ITM_StockTake)BindingSource.DataSource).ITM_StockTakeItem)
            {
                if (item.QuantityCount2 == null)
                {
                    item.QuantityCount2 = item.QuantityCount1;
                }

                //DB.VW_Inventory inventory = DataContext.ReadonlyContext.VW_Inventory.FirstOrDefault(n => n.Id == item.InventoryId);
                DB.SYS_DOC_Line line = BL.SYS.SYS_DOC_Line.New;
                line.LineItem = DataContext.ReadonlyContext.VW_LineItem.FirstOrDefault(n => n.Id == item.InventoryId);
                line.ItemId   = line.LineItem.Id;
                line.Quantity = item.QuantityCount2.Value - item.OnHand.Value;
                line.Amount   = line.LineItem.UnitAverage;
                line.Total    = line.Quantity * line.Amount;
                sys_header.SYS_DOC_Line.Add(line);
            }
            return(sys_header);
        }
Exemple #26
0
        /// <summary>
        /// Creates Goods Returned from Goods Received
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static DB.SYS_DOC_Header CreateGoodsReturnedFromGoodsReceived(DB.SYS_DOC_Header entity, DataContext dataContext)
        {
            DB.SYS_DOC_Header docHeader = CopyDocument(entity, dataContext);

            docHeader.TypeId = (byte)SYS.SYS_DOC_Type.GoodsReturned;

            //Remove lines that you have no received items for
            List <DB.SYS_DOC_Line> removeLines = new List <DB.SYS_DOC_Line>();

            foreach (DB.SYS_DOC_Line line in docHeader.SYS_DOC_Line.Where(n => (n.LineItem.TypeId == (byte)SYS.SYS_Type.Account && n.Amount == n.AmountCredited) ||
                                                                          (n.LineItem.TypeId == (byte)SYS.SYS_Type.Inventory && n.QtyReceived == 0)))
            {
                removeLines.Add(line);
            }
            removeLines.ForEach(n => docHeader.SYS_DOC_Line.Remove(n));

            //Populate Quantity on Goods Returned for returnable items
            foreach (DB.SYS_DOC_Line line in docHeader.SYS_DOC_Line.Where(n => (n.LineItem.TypeId == (byte)SYS.SYS_Type.Account && n.Amount != n.AmountCredited) ||
                                                                          (n.LineItem.TypeId == (byte)SYS.SYS_Type.Inventory && n.QtyReceived != 0)))
            {
                switch (line.LineItem.TypeId)
                {
                case (byte)SYS.SYS_Type.Account:
                    line.Amount = Math.Min(line.Amount, line.Amount - line.AmountCredited);
                    break;

                case (byte)SYS.SYS_Type.Inventory:
                    line.Quantity = Math.Min(line.Quantity, line.QtyReceived);
                    break;
                }
            }


            docHeader.Generated = true;
            return(docHeader);
        }
Exemple #27
0
        protected override bool SaveSuccessful()
        {
            try
            {
                DialogResult result = Essential.DocumentAlert.ShowAlert("Save Document", "You are about the save this document do you wish to continue?", Essential.DocumentAlert.Buttons.SaveAndPrint);
                if (result == System.Windows.Forms.DialogResult.Cancel)
                {
                    return(false);
                }

                using (new CDS.Client.Desktop.Essential.UTL.WaitCursor())
                {
                    this.OnSaveRecord();
                    if (!IsValid)
                    {
                        return(false);
                    }

                    string message   = "";
                    Int64  printerId = 0;
                    // Henko: Werner - WHAT THE HELL????!!!!!
                    //Incase something happens remove the current lines and add the ones in the grid
                    ((DB.SYS_DOC_Header)BindingSource.DataSource).SYS_DOC_Line.Clear();
                    lines.ForEach(n => ((DB.SYS_DOC_Header)BindingSource.DataSource).SYS_DOC_Line.Add(n));
                    switch (result)
                    {
                    case System.Windows.Forms.DialogResult.Yes:
                        printerId = BL.ApplicationDataContext.Instance.LoggedInUser.DefaultPrinterId.Value;
                        break;

                    case System.Windows.Forms.DialogResult.No:
                        printerId = 0;
                        break;
                    }
                    DB.SYS_DOC_Header entry = (DB.SYS_DOC_Header)BindingSource.DataSource;
                    if (IsNew)
                    {
                        entry.OriginForm = null;
                        message          = BL.ApplicationDataContext.Instance.Service.SaveDocument(entry, printerId);
                    }
                    else
                    {
                        try
                        {
                            if (lines.Where(n => n.NewJobLine == true).ToList().Count() > 0)
                            {
                                lines.Where(n => n.NewJobLine == true).ToList().ForEach(n => n.SYS_DOC_Header = null);
                                message = BL.ApplicationDataContext.Instance.Service.SaveJobLines(entry.Id, lines.Where(n => n.NewJobLine == true).ToList(), printerId);
                            }
                        }
                        catch (Exception ex)
                        {
                            DataContext.EntitySystemContext.RejectChanges();
                            return(false);
                        }
                    }
                    if (message.StartsWith("Success"))
                    {
                        ShowNotification("Document Saved", String.Format("{0} number {1} was saved successfully", this.Text, message.Split(',')[1]), 5000, false, null);

                        //Werner: Same issue as the Documents because the Entities are sent to the Service the are disjoint from the context and the Reject Changes cannot be checked
                        //I am making the assumption that when the service returns Success there will not be any further changes to the document
                        //On this Entity type you can change after you have made changes so when the grvItems_CellValueChanged is fired i will set this back to false
                        ForceClose = true;
                    }
                    else if (message.StartsWith("ChangesSaved"))
                    {
                        ShowNotification("Document Changes Saved", String.Format("{0} number {1} was saved successfully", this.Text, ((DB.SYS_DOC_Header)BindingSource.DataSource).DocumentNumber), 5000, false, null);
                        OpenRecord(((DB.SYS_DOC_Header)BindingSource.DataSource).Id);
                        if (lines.Count() == 0)
                        {
                            Close();
                        }

                        grvItems.RefreshData();
                        //Werner: Same issue as the Documents because the Entities are sent to the Service the are disjoint from the context and the Reject Changes cannot be checked
                        //I am making the assumption that when the service returns Success there will not be any further changes to the document
                        //On this Entity type you can change after you have made changes so when the grvItems_CellValueChanged is fired i will set this back to false
                        ForceClose = true;
                    }
                    else if (message != string.Empty)
                    {
                        DocumentSaveException(message);
                        return(false);
                    }
                    // Henko: Rewrite this WHOLE save method - UTTER CHAOS!!!!!
                    // Henko: I GUESS????? this means it has saved????
                    return(true);
                }
            }
            catch (Exception ex)
            {
                HasErrors        = true;
                CurrentException = ex;
                ((DB.SYS_DOC_Header)BindingSource.DataSource).SYS_DOC_Line.Clear();
                return(false);
            }
        }
Exemple #28
0
 public BuyoutDialogue(DB.SYS_DOC_Header sYS_DOC_Header)
 {
     InitializeComponent();
     SYS_DOC_Header = sYS_DOC_Header;
 }
Exemple #29
0
        /// <summary>
        /// Received AOR_Order object and created Purchase Order Documents
        /// </summary>
        /// <param name="order"></param>
        /// <param name="printer"></param>
        /// <returns></returns>
        public String GenerateOrder(long orderId, long createdBy, long printer)
        {
            string message = "";

            try
            {
                var order = BL.AOR.AOR_Order.Load(orderId, DataContext, new List <string>()
                {
                    "AOR_OrderLine"
                });
                BL.ApplicationDataContext.Instance.LoggedInUser = (DB.SEC_User)BL.SEC.SEC_User.LoadByPerson(createdBy, DataContext);
                BL.ApplicationDataContext.Instance.PopulateModuleAccess();
                BL.ApplicationDataContext.Instance.PopulateValidationRestrictions();
                decimal vatPercentage = BL.ApplicationDataContext.Instance.CompanySite.VatPercentage;
                List <DB.SYS_DOC_Header> purchaseOrders = new List <DB.SYS_DOC_Header>();
                foreach (var supplier in order.AOR_OrderLine.GroupBy(n => n.SupplierId).Select(n => new { EntityId = n.Key, Lines = n }))
                {
                    var supplierdetail = DataContext.ReadonlyContext.VW_Company.Where(n => n.EntityId == supplier.EntityId && n.TypeId == (byte)BL.ORG.ORG_Type.Supplier).Select(n => new { n.Id, CostCategory = n.CostCategoryId }).FirstOrDefault();

                    DB.SYS_DOC_Header header = BL.SYS.SYS_DOC_Document.New(BL.SYS.SYS_DOC_Type.PurchaseOrder);
                    header.ORG_TRX_Header                 = BL.ORG.ORG_TRX_Header.New;
                    header.ORG_TRX_Header.CompanyId       = supplierdetail.Id;
                    header.ORG_TRX_Header.ReferenceShort1 = orderId.ToString("D10");
                    System.Threading.Tasks.Parallel.ForEach(supplier.Lines, line =>
                    {
                        DB.SYS_DOC_Line docLine = BL.SYS.SYS_DOC_Line.New;
                        docLine.ItemId          = line.InventoryId;
                        docLine.LineItem        = DataContext.ReadonlyContext.VW_LineItem.FirstOrDefault(n => n.Id == docLine.ItemId);
                        docLine.Description     = line.Name;
                        docLine.Amount          = line.UnitCost.Value;
                        docLine.Quantity        = line.OrderAmount.Value;
                        docLine.Total           = line.Total.Value;
                        switch (supplierdetail.CostCategory)
                        {
                        case (byte)BL.ORG.ORG_CostCategory.SellingPriceIncludingSalesTax:
                            docLine.TotalTax = docLine.Total * vatPercentage / 100;
                            break;

                        case (byte)BL.ORG.ORG_CostCategory.SellingPriceExcludingSalesTax:
                            docLine.TotalTax = 0;
                            break;

                        case (byte)BL.ORG.ORG_CostCategory.CostIncludingSalesTax:
                            docLine.TotalTax = docLine.Total * vatPercentage / 100;
                            break;

                        case (byte)BL.ORG.ORG_CostCategory.CostExcludingSalesTax:
                            docLine.TotalTax = 0;
                            break;

                        case (byte)BL.ORG.ORG_CostCategory.AverageCostExcludingSalesTax:
                            docLine.TotalTax = 0;
                            break;
                        }
                        line.TotalTax = docLine.TotalTax;
                        lock (header.SYS_DOC_Line)
                        {
                            header.SYS_DOC_Line.Add(docLine);
                            docLine.LineOrder = header.SYS_DOC_Line.Count();
                        }
                    });
                    purchaseOrders.Add(header);
                }



                try
                {
                    purchaseOrders.ForEach(n =>
                    {
                        string result = SaveDocument(n, printer);
                        if (result.StartsWith("Exception"))
                        {
                            throw new Exception(result.Split(':')[1]);
                        }
                        else
                        {
                            message += String.Format(";{0},{1}", n.DocumentNumber, n.TrackId);
                        }
                    });

                    using (TransactionScope transaction = new TransactionScope())
                    {
                        order.OrderDate = BL.ApplicationDataContext.Instance.ServerDateTime;
                        BL.EntityController.SaveAOR_Order(order, DataContext);
                        DataContext.SaveChangesEntityOrderingContext();
                        DataContext.CompleteTransaction(transaction);
                    }
                    DataContext.EntityOrderingContext.AcceptAllChanges();
                }
                catch (Exception ex)
                {
                    DataContext.EntityOrderingContext.RejectChanges();
                    throw ex;
                }
            }
            catch (Exception ex)
            {
                return("Exception : " + ex.ToString());
            }
            return("Success" + message);
        }
Exemple #30
0
        private void RegisterPrintJob(long documentId, long printerId)
        {
            try
            {
                using (TransactionScope transaction = DataContext.GetTransactionScope())
                {
                    DB.SYS_Printer    printer  = BL.SYS.SYS_Printer.Load(printerId, DataContext);
                    DB.SYS_DOC_Header document = BL.SYS.SYS_DOC_Header.Load(documentId, DataContext);


                    switch (printer.PrinterType)
                    {
                    case "DOTMATRIX":
                        switch (document.TypeId)
                        {
                        case (byte)BL.SYS.SYS_DOC_Type.Quote:
                        case (byte)BL.SYS.SYS_DOC_Type.CreditNote:
                        case (byte)BL.SYS.SYS_DOC_Type.BackOrder:
                            DocumentPrinter.Instance.PrintDocument(printer.Location, printer.PrinterModel, SalesPrintTemplate.OuterXml, documentId, ConfigurationManager.ConnectionStrings["BaseConnection"].ConnectionString);
                            break;

                        case (byte)BL.SYS.SYS_DOC_Type.SalesOrder:
                            if (BL.SYS.SYS_DOC_Header.LoadByTrackId(document.TrackId, BL.SYS.SYS_DOC_Type.TAXInvoice, DataContext) != null)
                            {
                                document = BL.SYS.SYS_DOC_Header.LoadByTrackId(document.TrackId, BL.SYS.SYS_DOC_Type.TAXInvoice, DataContext);
                                DocumentPrinter.Instance.PrintDocument(printer.Location, printer.PrinterModel, SalesPrintTemplate.OuterXml, document.Id, ConfigurationManager.ConnectionStrings["BaseConnection"].ConnectionString);
                            }
                            break;

                        case (byte)BL.SYS.SYS_DOC_Type.TAXInvoice:
                            DocumentPrinter.Instance.PrintDocument(printer.Location, printer.PrinterModel, SalesPrintTemplate.OuterXml, documentId, ConfigurationManager.ConnectionStrings["BaseConnection"].ConnectionString);
                            break;

                        case (byte)BL.SYS.SYS_DOC_Type.PickingSlip:
                            DocumentPrinter.Instance.PrintDocument(printer.Location, printer.PrinterModel, PickingSlipSalesPrintTemplate.OuterXml, documentId, ConfigurationManager.ConnectionStrings["BaseConnection"].ConnectionString);
                            break;

                        case (byte)BL.SYS.SYS_DOC_Type.PurchaseOrder:
                        case (byte)BL.SYS.SYS_DOC_Type.GoodsReceived:
                        case (byte)BL.SYS.SYS_DOC_Type.GoodsReturned:
                            DocumentPrinter.Instance.PrintDocument(printer.Location, printer.PrinterModel, PurchaseSalesPrintTemplate.OuterXml, documentId, ConfigurationManager.ConnectionStrings["BaseConnection"].ConnectionString);
                            break;

                        case (byte)BL.SYS.SYS_DOC_Type.TransferRequest:
                        case (byte)BL.SYS.SYS_DOC_Type.TransferShipment:
                        case (byte)BL.SYS.SYS_DOC_Type.TransferReceived:
                        case (byte)BL.SYS.SYS_DOC_Type.InventoryAdjustment:
                            DocumentPrinter.Instance.PrintDocument(printer.Location, printer.PrinterModel, AdjustmentSalesPrintTemplate.OuterXml, documentId, ConfigurationManager.ConnectionStrings["BaseConnection"].ConnectionString);
                            break;

                        case (byte)BL.SYS.SYS_DOC_Type.Job:
                        case (byte)BL.SYS.SYS_DOC_Type.BOMAssemblyStarted:
                        case (byte)BL.SYS.SYS_DOC_Type.BOMDisassemblyStarted:
                        case (byte)BL.SYS.SYS_DOC_Type.BOMCanceled:
                        case (byte)BL.SYS.SYS_DOC_Type.BOMComplete:
                            DocumentPrinter.Instance.PrintDocument(printer.Location, printer.PrinterModel, WorkSalesPrintTemplate.OuterXml, documentId, ConfigurationManager.ConnectionStrings["BaseConnection"].ConnectionString);
                            break;
                        }
                        break;

                    case "INKJET":
                        PrintReportDocument(printer.Location, document.Title, document.TypeId.Value, documentId);
                        break;

                    case "RECEIPT":
                        switch (document.TypeId)
                        {
                        case (byte)BL.SYS.SYS_DOC_Type.Quote:
                        case (byte)BL.SYS.SYS_DOC_Type.CreditNote:
                        case (byte)BL.SYS.SYS_DOC_Type.BackOrder:
                            DocumentPrinter.Instance.PrintDocument(printer.Location, printer.PrinterModel, ReceiptSalesPrintTemplate.OuterXml, documentId, ConfigurationManager.ConnectionStrings["BaseConnection"].ConnectionString);
                            break;

                        case (byte)BL.SYS.SYS_DOC_Type.SalesOrder:
                            if (BL.SYS.SYS_DOC_Header.LoadByTrackId(document.TrackId, BL.SYS.SYS_DOC_Type.TAXInvoice, DataContext) != null)
                            {
                                document = BL.SYS.SYS_DOC_Header.LoadByTrackId(document.TrackId, BL.SYS.SYS_DOC_Type.TAXInvoice, DataContext);
                                if (printer.PrinterType == "RECEIPT")
                                {
                                    DocumentPrinter.Instance.PrintDocument(printer.Location, printer.PrinterModel, ReceiptSalesPrintTemplate.OuterXml, document.Id, ConfigurationManager.ConnectionStrings["BaseConnection"].ConnectionString);
                                }
                            }
                            break;

                        case (byte)BL.SYS.SYS_DOC_Type.TAXInvoice:
                            DocumentPrinter.Instance.PrintDocument(printer.Location, printer.PrinterModel, ReceiptSalesPrintTemplate.OuterXml, documentId, ConfigurationManager.ConnectionStrings["BaseConnection"].ConnectionString);
                            break;

                        case (byte)BL.SYS.SYS_DOC_Type.PickingSlip:
                            DocumentPrinter.Instance.PrintDocument(printer.Location, printer.PrinterModel, ReceiptSalesPrintTemplate.OuterXml, documentId, ConfigurationManager.ConnectionStrings["BaseConnection"].ConnectionString);
                            break;

                        case (byte)BL.SYS.SYS_DOC_Type.PurchaseOrder:
                        case (byte)BL.SYS.SYS_DOC_Type.GoodsReceived:
                        case (byte)BL.SYS.SYS_DOC_Type.GoodsReturned:
                            DocumentPrinter.Instance.PrintDocument(printer.Location, printer.PrinterModel, ReceiptSalesPrintTemplate.OuterXml, documentId, ConfigurationManager.ConnectionStrings["BaseConnection"].ConnectionString);
                            break;

                        case (byte)BL.SYS.SYS_DOC_Type.TransferRequest:
                        case (byte)BL.SYS.SYS_DOC_Type.TransferShipment:
                        case (byte)BL.SYS.SYS_DOC_Type.TransferReceived:
                        case (byte)BL.SYS.SYS_DOC_Type.InventoryAdjustment:
                            DocumentPrinter.Instance.PrintDocument(printer.Location, printer.PrinterModel, ReceiptSalesPrintTemplate.OuterXml, documentId, ConfigurationManager.ConnectionStrings["BaseConnection"].ConnectionString);
                            break;

                        case (byte)BL.SYS.SYS_DOC_Type.Job:
                        case (byte)BL.SYS.SYS_DOC_Type.BOMAssemblyStarted:
                        case (byte)BL.SYS.SYS_DOC_Type.BOMDisassemblyStarted:
                        case (byte)BL.SYS.SYS_DOC_Type.BOMCanceled:
                        case (byte)BL.SYS.SYS_DOC_Type.BOMComplete:
                            DocumentPrinter.Instance.PrintDocument(printer.Location, printer.PrinterModel, ReceiptSalesPrintTemplate.OuterXml, documentId, ConfigurationManager.ConnectionStrings["BaseConnection"].ConnectionString);
                            break;
                        }
                        break;
                    }

                    BL.ORG.ORG_TRX_Header.SetDateFirstPrinted(document.Id, BL.ApplicationDataContext.Instance.LoggedInUser.PersonId, DataContext);
                    BL.ORG.ORG_TRX_Header.SetDateLastPrinted(document.Id, BL.ApplicationDataContext.Instance.LoggedInUser.PersonId, DataContext);
                    DataContext.EntityOrganisationContext.SaveChanges();
                    DataContext.CompleteTransaction(transaction);
                }
                DataContext.EntityOrganisationContext.AcceptAllChanges();
            }
            catch (Exception ex)
            {
                DataContext.EntityOrganisationContext.RejectChanges();
                if (CDS.Shared.Exception.UserInterfaceExceptionHandler.HandleException(ref ex))
                {
                    throw ex;
                }
                throw new Exception("Failed to Register print job /n" + ex.ToString());
            }
        }