Ejemplo n.º 1
0
 private void CheckToBackToOrderInsertFormIfStuffsEmpty()
 {
     if (AllStuffsData.All(a => a.TotalStuffQuantity <= 0))
     {
         try { Navigation.PopAsync(); } catch (Exception) { }
     }
 }
Ejemplo n.º 2
0
        private void ToolbarItem_OrderPreviewForm_Activated(object sender, EventArgs e)
        {
            FocusedQuantityTextBoxId = null;
            if (SelectedPartner == null && !SettlementTypeId.HasValue)
            {
                App.ShowError("خطا", "مشتری و نحوه تسویه را مشخص کنید.", "خوب");
                return;
            }
            else if (SelectedPartner == null)
            {
                App.ShowError("خطا", "مشتری را مشخص کنید.", "خوب");
                return;
            }
            else if (!SettlementTypeId.HasValue)
            {
                App.ShowError("خطا", "نحوه تسویه را مشخص کنید.", "خوب");
                return;
            }

            var WithoutPriceStuffs = AllStuffsData.Where(a => a.Quantity != 0 && !a._UnitPrice.HasValue).ToList();

            if (WithoutPriceStuffs.Any())
            {
                var Message = "برخی اقلام در لیست قیمت این مشتری ثبت نشده اند:\n" + WithoutPriceStuffs.Select(a => a.StuffData.Name).Aggregate((sum, x) => sum + "\n" + x);
                App.ShowError("خطا", Message, "خوب");
                return;
            }

            SaleOrder SaleOrder;

            try
            {
                SaleOrder = MakeOrder(SelectedPartner.Id, SettlementTypeId.Value, DescriptionEditor.Text);
            }
            catch (Exception err)
            {
                App.ShowError("خطا", err.ProperMessage(), "خوب");
                return;
            }

            var OrderPreviewForm = new OrderPreviewForm(SaleOrder, OrdersForm, PartnerListForm, OrderInsertForm, this, true)
            {
                StartColor = Color.FromHex("ffffff"),
                EndColor   = Color.FromHex("ffffff")
            };

            this.Navigation.PushAsync(OrderPreviewForm);
        }
Ejemplo n.º 3
0
 public void UnitNameClicked(Guid StuffId)
 {
     FocusedQuantityTextBoxId = null;
     if (AllStuffsData != null)
     {
         var StuffModel = AllStuffsData.SingleOrDefault(a => a.StuffId == StuffId && !a.BatchNumberId.HasValue);
         if (StuffModel != null)
         {
             if (StuffModel.PackagesData.Count() > 1)
             {
                 var CurrentPackageIndex = StuffModel.PackagesData.Select((a, index) => new { a, index }).Single(a => StuffModel.SelectedPackage.Id == a.a.Package.Id).index;
                 var NewPackageIndex     = CurrentPackageIndex == StuffModel.PackagesData.Length - 1 ? 0 : CurrentPackageIndex + 1;
                 StuffModel.SelectedPackage = StuffModel.PackagesData[NewPackageIndex].Package;
             }
         }
     }
 }
Ejemplo n.º 4
0
 public void QuantityPlusClicked(Guid StuffId, Guid?BatchNumberId)
 {
     FocusedQuantityTextBoxId = null;
     if (AllStuffsData != null)
     {
         var StuffModel = AllStuffsData.SingleOrDefault(a => a.StuffId == StuffId);
         if (StuffModel != null)
         {
             if (BatchNumberId.HasValue)
             {
                 StuffModel = StuffModel.StuffRow_BatchNumberRows.SingleOrDefault(a => a.BatchNumberId == BatchNumberId);
             }
             if (BatchNumberId.HasValue || !StuffModel.HasBatchNumbers)
             {
                 StuffModel.Quantity++;
             }
         }
     }
 }
Ejemplo n.º 5
0
 public void QuantityMinusClicked(Guid StuffId, Guid?BatchNumberId)
 {
     FocusedQuantityTextBoxId = null;
     if (AllStuffsData != null)
     {
         var StuffModel = AllStuffsData.SingleOrDefault(a => a.StuffId == StuffId);
         if (StuffModel != null)
         {
             if (BatchNumberId.HasValue)
             {
                 StuffModel = StuffModel.StuffRow_BatchNumberRows.SingleOrDefault(a => a.BatchNumberId == BatchNumberId);
             }
             if (BatchNumberId.HasValue || !StuffModel.HasBatchNumbers)
             {
                 StuffModel.Quantity = StuffModel.Quantity > 0 ? StuffModel.Quantity - 1 : 0;
             }
         }
         CheckToBackToOrderInsertFormIfStuffsEmpty();
     }
 }
Ejemplo n.º 6
0
        private SaleOrder MakeOrder(Guid PartnerId, Guid SettlementTypeId, string Description)
        {
            var SaleOrder = new SaleOrder()
            {
                Id                    = EditingSaleOrderId.HasValue ? EditingSaleOrderId.Value : Guid.NewGuid(),
                PreCode               = null,
                InsertDateTime        = DateTime.Now,
                PartnerId             = PartnerId,
                SettlementTypeId      = SettlementTypeId,
                Description           = Description,
                CashPrise             = 0,
                DiscountPercent       = 0,
                GeoLocation_Latitude  = null, //TODO
                GeoLocation_Longitude = null, //TODO
                GeoLocation_Accuracy  = null, //TODO
                WarehouseId           = WarehouseId
            };

            var _SaleOrderStuffs = AllStuffsData.Where(a => !a.HasBatchNumbers).SelectMany(a => a.PackagesData.Where(b => b.Quantity != 0).Select(b => new { Stuff = a, BatchNumber = (DBRepository.StuffListModel)null, Package = b }))
                                   .Union(AllStuffsData.Where(a => a.HasBatchNumbers).SelectMany(a => a.StuffRow_BatchNumberRows.SelectMany(b => b.PackagesData.Where(c => c.Quantity != 0).Select(c => new { Stuff = a, BatchNumber = b, Package = c }))))
                                   .Select((a, index) => new
            {
                ArticleIndex    = index + 1,
                StuffData       = a.Stuff.StuffData,
                PackageData     = a.Package.Package,
                BatchNumberData = a.BatchNumber != null ? a.BatchNumber.BatchNumberData : null,
                Quantity        = a.Package.Quantity,
                PackagePrice    = a.Stuff._UnitPrice.Value * a.Package.Package.Coefficient
            }).Where(a => a.Quantity != 0).ToList();

            var MinSaleConflicts = _SaleOrderStuffs.GroupBy(a => a.StuffData).Where(a => a.Sum(b => b.Quantity * b.PackageData.Coefficient) < a.Key.MinForSale).ToArray();

            if (MinSaleConflicts.Any())
            {
                throw new Exception("کالا" + (MinSaleConflicts.Count() > 1 ? "ها" : "") + "ی زیر کمتر از حداقل تعیین شده در سیستم سفارش داده شده اند:\n" +
                                    MinSaleConflicts.Select(a => a.Key.Name + " (حداقل سفارش: " + a.Key.MinForSale + " " + a.Key.Packages.Single(b => b.Coefficient == 1).Name + ")").Aggregate((sum, x) => sum + "\n" + x));
            }

            var SaleCoefficientConflicts = _SaleOrderStuffs.Where(a => a.StuffData.SaleCoefficient != 0 && a.StuffData.SaleCoefficient != 1).GroupBy(a => a.StuffData).Where(a => a.Sum(b => b.Quantity * b.PackageData.Coefficient) % a.Key.SaleCoefficient != 0).ToArray();

            if (SaleCoefficientConflicts.Any())
            {
                throw new Exception("تعداد سفارش کالا" + (SaleCoefficientConflicts.Count() > 1 ? "ها" : "") + "ی زیر با ضریب فروش تعیین شده در سیستم مغایرت دارد:\n" +
                                    SaleCoefficientConflicts.Select(a => a.Key.Name + " (ضریب فروش: " + a.Key.SaleCoefficient + " " + a.Key.Packages.Single(b => b.Coefficient == 1).Name + ")").Aggregate((sum, x) => sum + "\n" + x));
            }

            var SaleOrderStuffs = _SaleOrderStuffs.Select(a => new SaleOrderStuff()
            {
                Id                    = Guid.NewGuid(),
                OrderId               = SaleOrder.Id,
                SaleOrder             = SaleOrder,
                ArticleIndex          = a.ArticleIndex,
                PackageId             = a.PackageData.Id,
                BatchNumberId         = a.BatchNumberData != null ? a.BatchNumberData.BatchNumberId : new Nullable <Guid>(),
                Quantity              = a.Quantity,
                SalePrice             = a.PackagePrice,
                DiscountPercent       = 0,
                VATPercent            = SaleOrder.Partner.CalculateVATForThisPerson && a.PackageData.Stuff.HasVAT ? App.VATPercent.Value : 0,
                FreeProduct           = false,
                FreeProduct_UnitPrice = null
            }).ToArray();

            var SaleOrderCashDiscounts = new CashDiscount[] { };

            SaleOrder.SaleOrderStuffs = SaleOrderStuffs;
            SaleOrder.CashDiscounts   = SaleOrderCashDiscounts;

            SaleOrder = App.DB.CalculateProporatedDiscount(SaleOrder);

            return(SaleOrder);
        }