예제 #1
0
        public Invoice CreateInvoiceFromSalesOrder(SalesOrder so)
        {
            if (so.SaleTypeENUM != SaleTypeEnum.Unknown || so.SaleTypeENUM == SaleTypeEnum.Quotation)
            {
                Invoice i = Factory();
                i.LoadFrom(so);
                i.SalesOrders.Add(so);


                if (!so.SalesOrderTrxs.IsNullOrEmpty())
                {
                    InvoiceTrxDAL iTrxDAL = new InvoiceTrxDAL(_db, _user);
                    foreach (var item in so.SalesOrderTrxs)
                    {
                        InvoiceTrx iTrx = iTrxDAL.CreateFrom(item);

                        iTrx.SalesOrderTrxs.Add(item);
                        i.InvoiceTrxs.Add(iTrx);
                    }
                }
                return(i);
            }

            return(null);
        }
예제 #2
0
        public Invoice CreateInvoiceFromManySalesOrders(List <SalesOrder> so)
        {
            if (!so.IsNullOrEmpty())
            {
                //Get all the totals of the products in case there are duplicates
                List <SalesOrderTrx> lstSalesOrderTrx = new List <SalesOrderTrx>();
                foreach (var item in so)
                {
                    if (item.SalesOrderTrxs.IsNullOrEmpty())
                    {
                        foreach (var salesOrderTrx in item.SalesOrderTrxs)
                        {
                            lstSalesOrderTrx.Add(salesOrderTrx);
                        }
                    }
                }

                //now lstSalesOrderTrx contains all the SalesOrderTrx of All the sales orders

                var lstSoProductsSummed = (from s in lstSalesOrderTrx
                                           group s by new { s.ProductID, s.FinalSalesPrice } into strGrp
                                           select new
                {
                    Key = strGrp.Key,
                    TotalOrdered = strGrp.Sum(x => x.OrderedQty),
                    TotalToShip = strGrp.Sum(x => x.ShipQty),
                    FinalSalesPrice = strGrp.Key.FinalSalesPrice
                })
                                          .ToList();

                if (!lstSoProductsSummed.IsNullOrEmpty())
                {
                    InvoiceTrxDAL    invTrxDAL = new InvoiceTrxDAL(_db, _user);
                    SalesOrderTrxDAL soTrxDAL  = new SalesOrderTrxDAL(_db, _user);

                    foreach (var item in lstSoProductsSummed)
                    {
                        InvoiceTrx i = invTrxDAL.Factory();
                        i.ProductID = item.Key.ProductID;

                        //Adds only those trxs where the product is the same.
                        i.SalesOrderTrxs   = lstSalesOrderTrx.Where(x => x.ProductID == i.ProductID).ToList();
                        i.MetaData.Comment = "Summed " + soTrxDAL.GetSoNameStringifyOf(i.SalesOrderTrxs);
                        i.FinalSalesPrice  = item.FinalSalesPrice;
                        i.OrderedQty       = item.TotalOrdered;
                        //i.ShippedQty = item.TotalToShip;
                    }
                }

                //Now we have the totals for each product. Now make 1 Salesorder Trxs got each and add
                //the So Trx that contains the product
            }
            return(null);
        }