public static CashDiscount CreateCashDiscount(string dataAreaId, string cashDiscountCode, decimal percent, int numberOfMonths, int numberOfDays)
 {
     CashDiscount cashDiscount = new CashDiscount();
     cashDiscount.dataAreaId = dataAreaId;
     cashDiscount.CashDiscountCode = cashDiscountCode;
     cashDiscount.Percent = percent;
     cashDiscount.NumberOfMonths = numberOfMonths;
     cashDiscount.NumberOfDays = numberOfDays;
     return cashDiscount;
 }
        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);
        }
Example #3
0
 /// <summary>   Converts this object to a row. </summary>
 /// <returns>   This object as a string. </returns>
 public string ToRow()
 {
     return
         ($"{Volume.ToDatev()};{Claim.ToDatev()};{CurrencySymbol.ToDatev()};{ExchangeRage.ToDatev()};{BasicVolume.ToDatev()};{BasicVolumeCurrencySymbol.ToDatev()};{AccountNumber.ToDatev()};{ContraAccountNumber.ToDatev()};{TaxKey.ToDatev()};{Date.ToShortDatevDate()};{DocumentField1.ToDatev()};{DocumentField2.ToDatev()};{CashDiscount.ToDatev()};{BookingText.ToDatev()};{Blocked.ToDatev()};{DiverseAccountNumber.ToDatev()};{PartnerBank.ToDatev()};{Circumstances.ToDatev()};{InterestBlock.ToDatev()};{DocumentLink.ToDatev()};{BookingInfoType1.ToDatev()};{BookingInfoContent1.ToDatev()};{BookingInfoType2.ToDatev()};{BookingInfoContent2.ToDatev()};{BookingInfoType3.ToDatev()};{BookingInfoContent3.ToDatev()};{BookingInfoType4.ToDatev()};{BookingInfoContent4.ToDatev()};{BookingInfoType5.ToDatev()};{BookingInfoContent5.ToDatev()};{BookingInfoType6.ToDatev()};{BookingInfoContent6.ToDatev()};{BookingInfoType7.ToDatev()};{BookingInfoContent7.ToDatev()};{BookingInfoType8.ToDatev()};{BookingInfoContent8.ToDatev()};{CostCenter1.ToDatev()};{CostCenter2.ToDatev()};{CostAmount.ToDatev()};{CountryCodeAndTaxId.ToDatev()};{EuroTax.ToDatev()};{DifferentTaxType.ToDatev()};{IntentionLL.ToDatev()};{FunctionLL.ToDatev()};{BU49FunctionType.ToDatev()};{BU49FunctionNumber.ToDatev()};{BU49FunctionAddition.ToDatev()};{AdditionalInfoType1.ToDatev()};{AdditionalInfoContent1.ToDatev()};{AdditionalInfoType2.ToDatev()};{AdditionalInfoContent2.ToDatev()};{AdditionalInfoType3.ToDatev()};{AdditionalInfoContent3.ToDatev()};{AdditionalInfoType4.ToDatev()};{AdditionalInfoContent4.ToDatev()};{AdditionalInfoType5.ToDatev()};{AdditionalInfoContent5.ToDatev()};{AdditionalInfoType6.ToDatev()};{AdditionalInfoContent6.ToDatev()};{AdditionalInfoType7.ToDatev()};{AdditionalInfoContent7.ToDatev()};{AdditionalInfoType8.ToDatev()};{AdditionalInfoContent8.ToDatev()};{AdditionalInfoType9.ToDatev()};{AdditionalInfoContent9.ToDatev()};{AdditionalInfoType10.ToDatev()};{AdditionalInfoContent10.ToDatev()};{AdditionalInfoType11.ToDatev()};{AdditionalInfoContent11.ToDatev()};{AdditionalInfoType12.ToDatev()};{AdditionalInfoContent12.ToDatev()};{AdditionalInfoType13.ToDatev()};{AdditionalInfoContent13.ToDatev()};{AdditionalInfoType14.ToDatev()};{AdditionalInfoContent14.ToDatev()};{AdditionalInfoType15.ToDatev()};{AdditionalInfoContent15.ToDatev()};{AdditionalInfoType16.ToDatev()};{AdditionalInfoContent16.ToDatev()};{AdditionalInfoType17.ToDatev()};{AdditionalInfoContent17.ToDatev()};{AdditionalInfoType18.ToDatev()};{AdditionalInfoContent18.ToDatev()};{AdditionalInfoType19.ToDatev()};{AdditionalInfoContent19.ToDatev()};{AdditionalInfoType20.ToDatev()};{AdditionalInfoContent20.ToDatev()};{Amount.ToDatev()};{Weight.ToDatev()};{PaymentType.ToDatev()};{ClaimType.ToDatev()};{CommunalYear.ToShortDatevYear()};{CommunalDueYear.ToShortDatevYear()};{CashDiscountType.ToDatev()};{OrderNumber.ToDatev()};{BookingType.ToDatev()};{TaxKeyPrepayment.ToDatev()};{CountryCodePrePayment.ToDatev()};{IntentionLLPrepayment.ToDatev()};{EuroTaxPrepayment.ToDatev()};{AccountNumberPrepayment.ToDatev()};\"SV\";{BookingGuid.ToDatev()};{CostDate.ToDatevDateReverse()};{SepaReference.ToDatev()};{CashDiscountBlock.ToDatev()};{Proprietor.ToDatev()};{ParticipantNumber.ToDatev()};{IdentificationNumber.ToDatev()};{PainterNumber.ToDatev()};{BatchBlockTill.ToDatevDateReverse()};{SoBilIntention.ToDatev()};{SoBilKey.ToDatev()};{Fixing.ToDatev()};{ActivityDate.ToDatevDateReverse()};{ActivityDate.ToDatevDateReverse()}");
 }