Ejemplo n.º 1
0
        //Create ArticleBag From DocumentFinanceMaster
        public static ArticleBag DocumentFinanceMasterToArticleBag(fin_documentfinancemaster pDocumentFinanceMaster)
        {
            //Log4Net
            log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            //Init Global ArticleBag
            ArticleBag           articleBag = new ArticleBag();
            ArticleBagKey        articleBagKey;
            ArticleBagProperties articleBagProps;

            try
            {
                if (pDocumentFinanceMaster != null &&
                    pDocumentFinanceMaster.DocumentDetail != null &&
                    pDocumentFinanceMaster.DocumentDetail.Count > 0
                    )
                {
                    foreach (fin_documentfinancedetail detail in pDocumentFinanceMaster.DocumentDetail)
                    {
                        //Prepare articleBag Key and Props
                        articleBagKey = new ArticleBagKey(
                            detail.Article.Oid,
                            detail.Designation,
                            detail.Price,
                            detail.Discount,
                            detail.Vat
                            );
                        articleBagProps = new ArticleBagProperties(
                            detail.DocumentMaster.SourceOrderMain.PlaceTable.Place.Oid,
                            detail.DocumentMaster.SourceOrderMain.PlaceTable.Oid,
                            (PriceType)detail.DocumentMaster.SourceOrderMain.PlaceTable.Place.PriceType.EnumValue,
                            detail.Code,
                            detail.Quantity,
                            detail.UnitMeasure
                            );
                        //Send to Bag
                        articleBag.Add(articleBagKey, articleBagProps);
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error(ex.Message, ex);
            }

            return(articleBag);
        }
Ejemplo n.º 2
0
        //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
        //Static Methods

        //Create ArticleBag From OrderMain.OrderTicket, and Discount PartialPayments for Working OrderMain
        public static ArticleBag TicketOrderToArticleBag(OrderMain pOrderMain)
        {
            //Log4Net
            log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            bool debug = false;

            //OrderMain
            OrderMain orderMain = pOrderMain;
            //ArticleBag
            ArticleBag           articleBag = new ArticleBag();
            ArticleBagKey        articleBagKey;
            ArticleBagProperties articleBagProps;

            //Removed, gives problems, Avoid used DropIdentityMap
            //GlobalFramework.SessionXpo.DropIdentityMap();

            try
            {
                if (orderMain.PersistentOid != Guid.Empty)
                {
                    string sqlOrders = string.Format(@"
                        SELECT 
                            dmOid AS DocumentOrderMain, ddArticle AS Article, ddDesignation AS Designation,ddPrice AS Price,ddDiscount AS Discount,ddVat AS Vat,ddVatExemptionReason AS VatExemptionReason,
                            cpOid AS ConfigurationPlace, ctOid AS ConfigurationPlaceTable, dtPriceType AS PriceType, ddCode AS Code, ddQuantity AS Quantity, ddUnitMeasure AS UnitMeasure,
                            ddToken1 as Token1, ddToken2 as Token2
                        FROM 
                            view_orders 
                        WHERE 
                            dmOid = '{0}'
                        ORDER BY 
                            dtTicketId
                        ;"
                                                     , orderMain.PersistentOid
                                                     );
                    XPSelectData selectedDataOrders = FrameworkUtils.GetSelectedDataFromQuery(sqlOrders);

                    //Process Tickets and Add to ArticleBag
                    if (selectedDataOrders.Data.Length > 0)
                    {
                        foreach (SelectStatementResultRow row in selectedDataOrders.Data)
                        {
                            //Generate Key/Props
                            articleBagKey = new ArticleBagKey(
                                new Guid(row.Values[selectedDataOrders.GetFieldIndex("Article")].ToString()),                                   //ticketLine.Article.Oid
                                Convert.ToString(row.Values[selectedDataOrders.GetFieldIndex("Designation")]),                                  //ticketLine.Designation
                                Convert.ToDecimal(row.Values[selectedDataOrders.GetFieldIndex("Price")]),                                       //ticketLine.Price
                                Convert.ToDecimal(row.Values[selectedDataOrders.GetFieldIndex("Discount")]),                                    //ticketLine.Discount
                                Convert.ToDecimal(row.Values[selectedDataOrders.GetFieldIndex("Vat")])                                          //ticketLine.Vat
                                );

                            articleBagProps = new ArticleBagProperties(
                                new Guid(row.Values[selectedDataOrders.GetFieldIndex("ConfigurationPlace")].ToString()),                        //ticket.PlaceTable.Place.Oid
                                new Guid(row.Values[selectedDataOrders.GetFieldIndex("ConfigurationPlaceTable")].ToString()),                   //ticket.PlaceTable.Oid
                                (PriceType)Enum.Parse(typeof(PriceType), row.Values[selectedDataOrders.GetFieldIndex("PriceType")].ToString()), //ticket.PriceType
                                Convert.ToString(row.Values[selectedDataOrders.GetFieldIndex("Code")]),                                         //ticketLine.Code
                                Convert.ToDecimal(row.Values[selectedDataOrders.GetFieldIndex("Quantity")]),                                    //ticketLine.Quantity
                                Convert.ToString(row.Values[selectedDataOrders.GetFieldIndex("UnitMeasure")])                                   //ticketLine.UnitMeasure
                                );

                            //Detect and Assign VatExemptionReason
                            if (row.Values[selectedDataOrders.GetFieldIndex("VatExemptionReason")] != null &&
                                Convert.ToString(row.Values[selectedDataOrders.GetFieldIndex("VatExemptionReason")]) != Guid.Empty.ToString()
                                )
                            {
                                //Add VatException Reason to Key
                                articleBagKey.VatExemptionReasonOid = new Guid(Convert.ToString(row.Values[selectedDataOrders.GetFieldIndex("VatExemptionReason")]));
                            }

                            //Tokens
                            articleBagProps.Token1 = Convert.ToString(row.Values[selectedDataOrders.GetFieldIndex("Token1")]); //ticketLine.Token1
                            articleBagProps.Token2 = Convert.ToString(row.Values[selectedDataOrders.GetFieldIndex("Token2")]); //ticketLine.Token2

                            //Send to Bag
                            if (articleBagProps.Quantity > 0)
                            {
                                articleBag.Add(articleBagKey, articleBagProps);
                            }

                            //if (debug) log.Debug(string.Format("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}\t{9}\t{10}", ticket.PlaceTable.Place.Oid, ticket.PlaceTable.Designation, ticket.PriceType, ticketLine.Article.Oid, ticketLine.Code, ticketLine.Designation, ticketLine.Price, ticketLine.Quantity, ticketLine.UnitMeasure, ticketLine.Discount, ticketLine.Vat));
                        }
                    }

                    //Process PartialPayed Items and Remove From ArticleBag
                    string sqlDocuments = string.Format(@"
                        SELECT 
                            ftOid AS DocumentType,fdArticle AS Article,fdDesignation AS Designation,fdPrice AS Price,fdQuantity AS Quantity, fdDiscount AS Discount, fdVat AS Vat, fdVatExemptionReason AS VatExemptionReason
                        FROM 
                            view_documentfinance 
                        WHERE 
                            fmSourceOrderMain = '{0}'
                        ORDER BY 
                            ftOid,fmOid
                        ;"
                                                        , orderMain.PersistentOid
                                                        );

                    XPSelectData selectedDataDocuments = FrameworkUtils.GetSelectedDataFromQuery(sqlDocuments);
                    if (selectedDataDocuments.Data.Length > 0)
                    {
                        foreach (SelectStatementResultRow row in selectedDataDocuments.Data)
                        {
                            // If Not ConferenceDocument or TableConsult
                            if (row.Values[selectedDataDocuments.GetFieldIndex("DocumentType")].ToString() != SettingsApp.XpoOidDocumentFinanceTypeConferenceDocument.ToString())
                            {
                                //Generate Key/Props
                                articleBagKey = new ArticleBagKey(
                                    new Guid(row.Values[selectedDataDocuments.GetFieldIndex("Article")].ToString()),
                                    Convert.ToString(row.Values[selectedDataDocuments.GetFieldIndex("Designation")]),
                                    Convert.ToDecimal(row.Values[selectedDataDocuments.GetFieldIndex("Price")]),
                                    Convert.ToDecimal(row.Values[selectedDataDocuments.GetFieldIndex("Discount")]),
                                    Convert.ToDecimal(row.Values[selectedDataDocuments.GetFieldIndex("Vat")])
                                    );
                                //Detect and Assign VatExemptionReason
                                if (row.Values[selectedDataDocuments.GetFieldIndex("VatExemptionReason")] != null &&
                                    Convert.ToString(row.Values[selectedDataDocuments.GetFieldIndex("VatExemptionReason")]) != Guid.Empty.ToString()
                                    )
                                {
                                    //Add VatException Reason to Key
                                    articleBagKey.VatExemptionReasonOid = new Guid(Convert.ToString(row.Values[selectedDataDocuments.GetFieldIndex("VatExemptionReason")]));
                                }
                                if (articleBag.ContainsKey(articleBagKey))
                                {
                                    //Remove PartialPayed Item Quantity from ArticleBag
                                    articleBag.Remove(articleBagKey, Convert.ToDecimal(row.Values[selectedDataDocuments.GetFieldIndex("Quantity")]));
                                }
                                else
                                {
                                    if (debug)
                                    {
                                        log.Debug(string.Format("articleBagKey: [{0}]", articleBagKey));
                                    }
                                }
                            }
                        }
                    }
                    if (debug)
                    {
                        articleBag.ShowInLog();
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error(ex.Message, ex);
            }

            return(articleBag);
        }