Exemple #1
0
        public StockTakingProtocol(StockTaking stockTaking)
            : this()
        {
            ProtocolDate   = BusinessDomain.GetFormattedDate(stockTaking.Date);
            ProtocolNumber = stockTaking.FormattedOperationNumber;
            Note           = stockTaking.Note;

            CompanyRecord company = CompanyRecord.GetDefault();

            CompanyName         = company.Name;
            CompanyNumber       = company.Bulstat;
            CompanyCity         = company.City;
            CompanyAddress      = company.Address;
            CompanyTelephone    = company.Telephone;
            CompanyLiablePerson = company.LiablePerson;

            Location = stockTaking.Location2;

            double vat = stockTaking.VAT;

            if (BusinessDomain.AppConfiguration.VATIncluded)
            {
                Total        = Currency.ToString(stockTaking.Total - vat);
                Vat          = Currency.ToString(vat);
                TotalPlusVat = stockTaking.Total;
            }
            else
            {
                Total        = Currency.ToString(stockTaking.Total);
                Vat          = Currency.ToString(vat);
                TotalPlusVat = stockTaking.Total + vat;
            }

            int i = 1;

            foreach (StockTakingDetail detail in stockTaking.Details)
            {
                StockTakingProtocolDetail stockTakingProtocolDetail = new StockTakingProtocolDetail(i++, detail, false);
                stockTakingProtocolDetail.ExpectedQuantity = Quantity.ToString(detail.ExpectedQuantity);
                stockTakingProtocolDetail.EnteredQuantity  = Quantity.ToString(detail.EnteredQuantity);
                StockTakingProtocolDetails.Add(stockTakingProtocolDetail);
            }

            TotalQuantity = Quantity.ToString(stockTaking.Details.Sum(d => d.EnteredQuantity));
        }
Exemple #2
0
        public WasteProtocol(Waste waste)
            : this()
        {
            ProtocolDate   = BusinessDomain.GetFormattedDate(waste.Date);
            ProtocolNumber = waste.FormattedOperationNumber;
            Note           = waste.Note;

            CompanyRecord company = CompanyRecord.GetDefault();

            CompanyName         = company.Name;
            CompanyNumber       = company.Bulstat;
            CompanyCity         = company.City;
            CompanyAddress      = company.Address;
            CompanyTelephone    = company.Telephone;
            CompanyLiablePerson = company.LiablePerson;

            Location = waste.Location2;
            bool      usePriceIn = !BusinessDomain.LoggedUser.HideItemsPurchasePrice;
            PriceType priceType  = usePriceIn ? PriceType.PurchaseTotal : PriceType.SaleTotal;

            double vat = waste.VAT;

            if (BusinessDomain.AppConfiguration.VATIncluded)
            {
                Total        = Currency.ToString(waste.Total - vat, priceType);
                Vat          = Currency.ToString(vat, priceType);
                TotalPlusVat = waste.Total;
            }
            else
            {
                Total        = Currency.ToString(waste.Total, priceType);
                Vat          = Currency.ToString(vat, priceType);
                TotalPlusVat = waste.Total + vat;
            }

            int i = 1;

            foreach (WasteDetail detail in waste.Details)
            {
                ProtocolDetails.Add(new ProtocolDetail(i++, detail, usePriceIn));
            }

            TotalQuantity = Quantity.ToString(waste.Details.Sum(d => d.Quantity));
        }
        public PurchaseReceipt(Purchase purchase)
            : this()
        {
            ReceiptDate   = BusinessDomain.GetFormattedDate(purchase.Date);
            ReceiptNumber = purchase.FormattedOperationNumber;
            Note          = purchase.Note;

            Invoice invoice = Invoice.GetReceivedForOperation(purchase.Id);

            if (invoice != null)
            {
                InvoiceDate   = invoice.DateString;
                InvoiceNumber = invoice.NumberString;
            }

            FillRecipient();
            FillSupplier(purchase.PartnerId);

            Location = purchase.Location2;

            double vat = purchase.VAT;

            if (BusinessDomain.AppConfiguration.VATIncluded)
            {
                Total        = purchase.Total - vat;
                Vat          = Currency.ToString(vat, PriceType.Purchase);
                TotalPlusVat = purchase.Total;
            }
            else
            {
                Total        = purchase.Total;
                Vat          = Currency.ToString(vat, PriceType.Purchase);
                TotalPlusVat = purchase.Total + vat;
            }

            int i = 1;

            foreach (PurchaseDetail detail in purchase.Details)
            {
                ReceiptDetails.Add(new ReceiptDetail(i++, detail));
            }

            TotalQuantity = Quantity.ToString(purchase.Details.Sum(d => d.Quantity));
        }
Exemple #4
0
        public TransferReceipt(Transfer transfer)
            : this()
        {
            ReceiptDate   = BusinessDomain.GetFormattedDate(transfer.Date);
            ReceiptNumber = transfer.FormattedOperationNumber;
            Note          = transfer.Note;

            FillSupplier();

            SourceLocation = transfer.SourceLocation2;
            TargetLocation = transfer.TargetLocation2;
            Transfer clone = transfer.Clone <Transfer, TransferDetail> ();

            if (BusinessDomain.AppConfiguration.AlwaysPrintTransfersUsingSalePrices)
            {
                clone.SetUsePriceIn(false);
            }

            int i = 1;

            foreach (TransferDetail detail in clone.Details)
            {
                detail.TotalEvaluate();
                ReceiptDetails.Add(new ReceiptDetail(i++, detail, clone.GetUsePriceIn()));
            }

            double vat = clone.VAT;

            if (BusinessDomain.AppConfiguration.VATIncluded)
            {
                Total        = Currency.ToString(clone.Total - vat, clone.TotalsPriceType);
                Vat          = Currency.ToString(vat, clone.TotalsPriceType);
                TotalPlusVat = clone.Total;
            }
            else
            {
                Total        = Currency.ToString(clone.Total, clone.TotalsPriceType);
                Vat          = Currency.ToString(vat, clone.TotalsPriceType);
                TotalPlusVat = clone.Total + vat;
            }

            TotalQuantity = Quantity.ToString(clone.Details.Sum(d => d.Quantity));
        }
Exemple #5
0
        public SaleReceipt(Sale sale)
            : this()
        {
            ReceiptDate   = BusinessDomain.GetFormattedDate(sale.Date);
            ReceiptNumber = sale.FormattedOperationNumber;
            Note          = sale.Note;

            FillRecipient(sale.PartnerId);
            FillSupplier();

            Location = sale.Location2;

            double vat = sale.VAT;

            if (BusinessDomain.AppConfiguration.VATIncluded)
            {
                Total        = sale.Total - vat;
                Vat          = Currency.ToString(vat);
                TotalPlusVat = sale.Total;
            }
            else
            {
                Total        = sale.Total;
                Vat          = Currency.ToString(vat);
                TotalPlusVat = sale.Total + vat;
            }

            int i = 1;

            foreach (SaleDetail detail in sale.Details)
            {
                ReceiptDetails.Add(new ReceiptDetail(i++, detail, false));
            }

            TotalQuantity = Quantity.ToString(sale.Details.Sum(d => d.Quantity));
        }
        public override string ToString()
        {
            string action = null;
            Item   item;

            if (!error)
            {
                switch (Type)
                {
                case PriceRule.ActionType.Stop:
                case PriceRule.ActionType.Exit:
                case PriceRule.ActionType.Message:
                    action = values.Length > 0 ? values [0].ToString() : null;
                    break;

                case PriceRule.ActionType.Email:
                    action = values.Length > 1 ? String.Format("{0}: {1}; {2}: {3}",
                                                               Translator.GetString("Message"), values [0],
                                                               Translator.GetString("Receiver"), values [1]) : null;
                    break;

                case PriceRule.ActionType.AddGood:
                case PriceRule.ActionType.AddGlobalGood:
                    List <string> ret = new List <string> ();
                    if (values != null)
                    {
                        foreach (SaleDetail saleDetail in values.OfType <SaleDetail> ())
                        {
                            item = Item.Cache.GetById(saleDetail.ItemId);
                            if (item == null)
                            {
                                continue;
                            }

                            ret.Add(String.Format("{0}: {1}; {2}: {3}; {4}: {5}",
                                                  Translator.GetString("Item"),
                                                  item.Name,
                                                  Translator.GetString("Quantity"),
                                                  Quantity.ToString(saleDetail.Quantity),
                                                  Translator.GetString("Price"),
                                                  Currency.ToString(saleDetail.PriceOut)));
                        }
                    }

                    action = ret.Count > 0 ? String.Join(Environment.NewLine, ret) : null;
                    break;

                case PriceRule.ActionType.Price:
                    if (values == null || values.Length == 0)
                    {
                        break;
                    }

                    if (values.Length == 1)
                    {
                        action = Currency.ToString((double)values [0]);
                        break;
                    }

                    if (values.Length < 3)
                    {
                        break;
                    }

                    string priceGroupString = String.Empty;
                    foreach (KeyValuePair <int, string> keyValuePair in Currency.GetAllPriceRulePriceGroups())
                    {
                        if (keyValuePair.Key == (int)values [0])
                        {
                            priceGroupString = keyValuePair.Value;
                            break;
                        }
                    }

                    string operatorString = String.Empty;
                    switch ((OperatorType)values [1])
                    {
                    case OperatorType.Plus:
                        operatorString = "+";
                        break;

                    case OperatorType.Minus:
                        operatorString = "-";
                        break;

                    case OperatorType.Multiply:
                        operatorString = "*";
                        break;

                    case OperatorType.Divide:
                        operatorString = "/";
                        break;
                    }
                    return(String.Format("{0} {1} {2}", priceGroupString, operatorString, (double)values [2]));

                case PriceRule.ActionType.Discount:
                    return(Percent.ToString((double)values [0]));

                case PriceRule.ActionType.ServiceCharge:
                    item = (Item)values [0];
                    return(String.Format("{0}: {1}; {2}: {3}",
                                         Translator.GetString("Item"),
                                         item.Name,
                                         values [1] is double?Translator.GetString("Percent") : Translator.GetString("Value"),
                                             values [1] is double?Percent.ToString((double)values [1]) : values [1]));

                case PriceRule.ActionType.Payment:
                case PriceRule.ActionType.AskAdvancePayment:
                    return(String.Format("{0} {1}", Percent.ToString((double)values [0]), Translator.GetString("of operation total")));

                default:
                    action = formula;
                    break;
                }
            }

            return(action ?? Translator.GetString("Error!"));
        }
        public override string ToString()
        {
            string condition = formula;
            long   id;

            switch (type)
            {
            case PriceRule.ConditionType.Partner:
                if (values [0] == null)
                {
                    condition = null;
                    break;
                }
                var partner = Partner.Cache.GetById(Convert.ToInt64(values [0]));
                condition = partner != null ? partner.Name : null;
                break;

            case PriceRule.ConditionType.PartnerGroup:
                if (values [0] == null)
                {
                    condition = null;
                    break;
                }

                var partnersGroup = Int64.TryParse((string)values [0], out id) ?
                                    PartnersGroup.Cache.GetById(id) :
                                    PartnersGroup.Cache.GetByCode((string)values [0]);

                condition = partnersGroup != null ? partnersGroup.Name : null;
                break;

            case PriceRule.ConditionType.Object:
                if (values [0] == null)
                {
                    condition = null;
                    break;
                }
                var location = Location.Cache.GetById(Convert.ToInt64(values [0]));
                condition = location != null ? location.Name : null;
                break;

            case PriceRule.ConditionType.ObjectGroup:
                if (values [0] == null)
                {
                    condition = null;
                    break;
                }

                var locationsGroup = Int64.TryParse((string)values [0], out id) ?
                                     LocationsGroup.Cache.GetById(id) :
                                     LocationsGroup.Cache.GetByCode((string)values [0]);

                condition = locationsGroup != null ? locationsGroup.Name : null;
                break;

            case PriceRule.ConditionType.User:
                if (values [0] == null)
                {
                    condition = null;
                    break;
                }
                var user = User.Cache.GetById(Convert.ToInt64(values [0]));
                condition = user != null ? user.Name : null;
                break;

            case PriceRule.ConditionType.UserGroup:
                if (values [0] == null)
                {
                    condition = null;
                    break;
                }

                var usersGroup = Int64.TryParse((string)values [0], out id) ?
                                 UsersGroup.Cache.GetById(id) :
                                 UsersGroup.Cache.GetByCode((string)values [0]);

                condition = usersGroup != null ? usersGroup.Name : null;
                break;

            case PriceRule.ConditionType.Good:
            case PriceRule.ConditionType.ContainsGood:
                if (values [0] == null)
                {
                    condition = null;
                    break;
                }
                var item = Item.Cache.GetById(Convert.ToInt64(values [0]));
                condition = item != null ? item.Name : null;
                break;

            case PriceRule.ConditionType.GoodGroup:
            case PriceRule.ConditionType.ContainsGGroup:
                if (values [0] == null)
                {
                    condition = null;
                    break;
                }

                var itemsGroup = Int64.TryParse((string)values [0], out id) ?
                                 ItemsGroup.Cache.GetById(id) :
                                 ItemsGroup.Cache.GetByCode((string)values [0]);

                condition = itemsGroup != null ? itemsGroup.Name : null;
                break;

            case PriceRule.ConditionType.Time:
                DateTime?timeFrom = (DateTime?)values [0];
                DateTime?timeTo   = (DateTime?)values [1];

                string timeFromString = timeFrom != null?
                                        String.Format("{0} {1}", Translator.GetString("from"), BusinessDomain.GetFormattedTime(timeFrom.Value)) :
                                            null;

                string timeToString = timeTo != null?
                                      String.Format("{0} {1}", Translator.GetString("to"), BusinessDomain.GetFormattedTime(timeTo.Value)) :
                                          null;

                if (timeFrom != null && timeTo != null)
                {
                    condition = String.Format("{0} {1}", timeFromString, timeToString);
                }
                else if (timeFrom != null)
                {
                    condition = timeFromString;
                }
                else if (timeTo != null)
                {
                    condition = timeToString;
                }
                else
                {
                    condition = null;
                }

                break;

            case PriceRule.ConditionType.Date:
                DateTime?dateFrom = (DateTime?)values [0];
                DateTime?dateTo   = (DateTime?)values [1];

                string dateFromString = dateFrom != null?
                                        String.Format("{0} {1}", Translator.GetString("from"), BusinessDomain.GetFormattedDate(dateFrom.Value)) :
                                            null;

                string dateToString = dateTo != null?
                                      String.Format("{0} {1}", Translator.GetString("to"), BusinessDomain.GetFormattedDate(dateTo.Value)) :
                                          null;

                if (dateFrom != null && dateTo != null)
                {
                    condition = String.Format("{0} {1}", dateFromString, dateToString);
                }
                else if (dateFrom != null)
                {
                    condition = dateFromString;
                }
                else if (dateTo != null)
                {
                    condition = dateToString;
                }
                else
                {
                    condition = null;
                }

                break;

            case PriceRule.ConditionType.DocumentSum:
            case PriceRule.ConditionType.TurnoverSum:
            case PriceRule.ConditionType.GoodQttySum:
            case PriceRule.ConditionType.PaymentSum:
            case PriceRule.ConditionType.UnpaidDocumentsSum:
                double?from = values [0] == null ? (double?)null : Convert.ToDouble(values [0]);
                double?to   = values [1] == null ? (double?)null : Convert.ToDouble(values [1]);
                string fromString;
                string toString;

                if (from != null)
                {
                    fromString = String.Format("{0} {1}", Translator.GetString("from"), type == PriceRule.ConditionType.GoodQttySum ?
                                               Quantity.ToString(from.Value) : Currency.ToString(from.Value, PriceType.Unknown));
                }
                else
                {
                    fromString = null;
                }

                if (to != null)
                {
                    toString = String.Format("{0} {1}", Translator.GetString("to"), type == PriceRule.ConditionType.GoodQttySum ?
                                             Quantity.ToString(to.Value) : Currency.ToString(to.Value, PriceType.Unknown));
                }
                else
                {
                    toString = null;
                }

                if (from != null && to != null)
                {
                    condition = String.Format("{0} {1}", fromString, toString);
                }
                else if (from != null)
                {
                    condition = fromString;
                }
                else if (to != null)
                {
                    condition = toString;
                }
                else
                {
                    condition = null;
                }

                break;

            case PriceRule.ConditionType.Weekdays:
                condition = String.Join(" ", ((IList <DayOfWeek>)values [0])
                                        .Select(DateTimeFormatInfo.CurrentInfo.GetAbbreviatedDayName)
                                        .ToArray());
                break;

            case PriceRule.ConditionType.PaymentTypeUsed:
                condition = String.Join(" ", ((IList <BasePaymentType>)values [0])
                                        .Select(PaymentType.GetBasePaymentTypeName)
                                        .ToArray());
                break;

            case PriceRule.ConditionType.DatabaseUpdated:
                DateTime now = DateTime.Now;
                condition = String.Format(Translator.GetString("Sooner than {0}"), now.AddMinutes(-30).ToFriendlyTimeAgoString(now));
                break;
            }

            if (condition == null)
            {
                error = true;
            }

            return(String.Format("{0}: {1}", TypeToString(type),
                                 condition ?? AllMissingErrors [type]));
        }