Exemple #1
0
        public static void SaveTransaction(OINV_Sales obj)
        {
            lock (Extensions.Locker)
            {
                var db = ContextFactory.GetDBContext();

                var transfers = obj.INV1_SalesDetail.Select(t => new OINM_Transaction(obj, t)).ToList();

                transfers.ForEach(t => db.OINM_Transaction.Add(t));

                ContextFactory.SaveChanges();

                //Actualizar existencias

                //var articles = (from detail in obj.INV1_SalesDetail
                //                join article in db.OITW_BranchArticles on detail.ItemCode equals article.ItemCode
                //                where article.WhsCode == detail.WhsCode
                //                select article).ToList();

                //articles.ForEach(a =>
                //{
                //    var detail = obj.INV1_SalesDetail.FirstOrDefault(d => d.ItemCode == a.ItemCode);
                //    a.OnHand = a.OnHand - detail.Quantity;
                //    a.OnHand1 = a.OnHand1 - detail.Quantity;
                //});

                //ContextFactory.SaveChanges();
                StoredCallbackProcessor.UpdateStock();
            }
        }
        public static bool ExistCreditNote(OINV_Sales SelectedSale)
        {
            var ex = ContextFactory.GetDBContext()
                     .RIN1_ClientCreditNoteDetail.Any(
                ccd => ccd.BaseDocNum == SelectedSale.DocNum && ccd.BaseEntry == SelectedSale.DocEntry);

            return(ex);
        }
Exemple #3
0
        public static bool VerifyNumAtCard(OINV_Sales selectedSale)
        {
            lock (Extensions.Locker)
            {
                var db = ContextFactory.GetDBContext();

                return(db.OINV_Sales.Any(s => s.NumAtCard == selectedSale.NumAtCard && s.IdSaleL != selectedSale.IdSaleL));
            }
        }
Exemple #4
0
        private static OINV_Sales SyncUpload(OINV_Sales sale)
        {
            var result = WebApiClient.AddSale(sale).Result;

            sale.UpdateModelPropertiesFrom(result.Model);
            sale.StateL = LocalStatus.Procesado;
            result.UpdateEntityVersion();


            SalesHelper.SaveTransaction(sale);
            return(sale);
        }
Exemple #5
0
        public static ODPI_DownPayment GetDownPaymentInSale(OINV_Sales sale, bool asNotrack)
        {
            lock (Extensions.Locker)
            {
                var db = ContextFactory.GetDBContext();
                return(asNotrack ?
                       db.ODPI_DownPayment.Include("DPI1_DownPaymentDetail").AsNoTracking()
                       .FirstOrDefault(dp => dp.CardCode == sale.CardCode && dp.DocEntry == sale.dpEntry):

                       db.ODPI_DownPayment.Include("DPI1_DownPaymentDetail")
                       .FirstOrDefault(dp => dp.CardCode == sale.CardCode && dp.DocEntry == sale.dpEntry));
            }
        }
Exemple #6
0
 public static OINV_Sales Synchronize(OINV_Sales model)
 {
     CheckForUpdates();// Actualizar cambios antes de subir y verificar si el objeto no fue ya procesado
     model = SalesHelper.Get(model.IdSaleL);
     if (model.StateL != LocalStatus.Procesado)
     {
         return(model.Upload(SyncUpload));
     }
     else
     {
         return(model);
     }
 }
Exemple #7
0
        public static void DeleteSale(OINV_Sales selectedSale)
        {
            if (selectedSale == null)
            {
                return;
            }

            lock (Extensions.Locker)
            {
                var db = ContextFactory.GetDBContext();

                db.OINV_Sales.Remove(selectedSale);
            }
        }
Exemple #8
0
 public override void ExecuteNewCommand()
 {
     ErrorMessage        = string.Empty;
     SelectedSale        = null;
     SelectedPartner     = null;
     SelectedDownPayment = null;
     HasDownPayment      = false;
     Serie                  = null;
     UserIsValid            = false;
     SelectedSale           = new OINV_Sales();
     selectedSale.DocDate   = DateTime.Now;
     SalesDetailsCollection = null;
     FormTitle              = "Detalle de Nueva Venta";
     ShowDialog(new SaleDetailsView(), this, resizeMode: ResizeMode.CanResize);
 }
Exemple #9
0
        public static List <InvoicePayment> GetiInvoicePayments(OINV_Sales sale)
        {
            lock (Extensions.Locker)
            {
                var db = ContextFactory.GetDBContext();

                var cashAccount = db.PaymentTypes
                                  .FirstOrDefault(p => p.IdPaymentType == 1); // Cuenta para efectivo

                var creditAccount = db.PaymentTypes
                                    .FirstOrDefault(p => p.IdPaymentType == 2); // Cuenta para tarjeta..


                var TDate = sale.DocDate;


                var pagosaloha = (from inaloha in db.InvoiceALOHAs
                                  where inaloha.Date == TDate
                                  select new
                {
                    alohaid = inaloha.IdInvoiceALOHA,
                    cash = inaloha.Cash,
                    credit = inaloha.Credit,
                }).FirstOrDefault();

                var pagos = new List <InvoicePayment>();

                //pago en efectivo
                var pagoe = new InvoicePayment();
                pagoe.WhsCode     = Config.WhsCode;
                pagoe.Amount      = pagosaloha.cash;
                pagoe.PaymentType = cashAccount;

                pagos.Add(pagoe);

                //pago tarjeta
                var pagot = new InvoicePayment();
                pagot.WhsCode     = Config.WhsCode;
                pagot.Amount      = pagosaloha.credit;
                pagot.PaymentType = creditAccount;

                pagos.Add(pagot);

                return(pagos);
            }
        }
Exemple #10
0
 public static void AddSale(OINV_Sales selectedSale)
 {
     if (selectedSale == null)
     {
         return;
     }
     lock (Extensions.Locker)
     {
         var db = ContextFactory.GetDBContext();
         if (selectedSale.IdSaleL == 0)
         {
             db.OINV_Sales.Add(selectedSale);
         }
         else
         {
             selectedSale.ModifiedDateL = DateTime.Now;
             selectedSale.ModifiedByL   = Config.CurrentUser;
         }
     }
 }
Exemple #11
0
        //private decimal GetOnHandFromProduct(OITM_Articles product)
        //{
        //    var branchArticle = product.OITW_BranchArticles.Where(p => p.ItemCode == product.ItemCode)
        //                .Select(p => p.OnHand1);
        //    var onHand = branchArticle.Any() ? branchArticle.FirstOrDefault().Value : (decimal)0;
        //    return onHand;
        //}

        private void GetSelectedArticle(OITM_Articles article)
        {
            IsModalVisible = false;

            if (SelectedSale == null)
            {
                SelectedSale = new OINV_Sales();
            }

            if (SelectedSale == null)
            {
                return;
            }

            var detail = new INV1_SalesDetail()
            {
                ItemCode  = article.ItemCode,
                Price     = articleChooserViewModel.ProductPriceDecimal,
                Quantity  = articleChooserViewModel.Quantity,
                LineTotal = articleChooserViewModel.TotalPriceToDecimal,
                //todo:    OITM_Articles = article
                OnHand      = ArticlesHelper.GetOnHandFor(article.ItemCode), // GetOnHandFromProduct(article),
                PriceEdited = article.PriceEdited,
                //TaxCode =  SelectedSerie!=null && SelectedSerie.Series==43 ? "IVACOF":"IVACRF",// quemado por juan
                Dscription = article.ItemName,
            };

            SelectedSale.INV1_SalesDetail.Add(detail);
            articleChooserViewModel.CleanFields();

            detailsCollection.Add(detail);
            RaisePropertyChanged("SalesDetailsCollection");
            IsFocusedAddButton = true;

            if (OnSelectedArticle != null)
            {
                OnSelectedArticle();
            }
        }
Exemple #12
0
 public static Task <Synchro <OINV_Sales> > AddSale(OINV_Sales sale)
 {
     return(PostAsync <OINV_Sales, Synchro <OINV_Sales> >("api/sales", sale));
 }