Пример #1
0
        public override InvoiceItem SaveOrUpdateInvoiceItem(InvoiceItem invoiceItem)
        {
            if (invoiceItem != null && invoiceItem.ID > 0)
                ResetCache(invoiceItem.ID);

            return base.SaveOrUpdateInvoiceItem(invoiceItem);
        }
Пример #2
0
        public virtual InvoiceItem SaveOrUpdateInvoiceItem(InvoiceItem invoiceItem)
        {
            _cache.Remove(_invoiceItemCacheKey);
            _cache.Insert(_invoiceItemCacheKey, String.Empty);

            using (var db = GetDb())
            {
                return SaveOrUpdateInvoiceItem(invoiceItem, db);
            }
        }
Пример #3
0
        private InvoiceItem SaveOrUpdateInvoiceItem(InvoiceItem invoiceItem, DbManager db)
        {
            if (invoiceItem.Price <= 0 || String.IsNullOrEmpty(invoiceItem.Title))
                throw new ArgumentException();

            if (!CRMSecurity.IsAdmin) CRMSecurity.CreateSecurityException();

            if (String.IsNullOrEmpty(invoiceItem.Description)) {
                invoiceItem.Description = String.Empty;
            }
            if (String.IsNullOrEmpty(invoiceItem.StockKeepingUnit))
            {
                invoiceItem.StockKeepingUnit = String.Empty;
            }

            if (!IsExist(invoiceItem.ID, db))
            {
                invoiceItem.ID = db.ExecuteScalar<int>(
                               Insert("crm_invoice_item")
                              .InColumnValue("id", 0)
                              .InColumnValue("title", invoiceItem.Title)
                              .InColumnValue("description", invoiceItem.Description)
                              .InColumnValue("stock_keeping_unit", invoiceItem.StockKeepingUnit)
                              .InColumnValue("price", invoiceItem.Price)
                              .InColumnValue("quantity", invoiceItem.Quantity)
                              .InColumnValue("stock_quantity", invoiceItem.StockQuantity)
                              .InColumnValue("track_inventory", invoiceItem.TrackInventory)
                              .InColumnValue("invoice_tax1_id", invoiceItem.InvoiceTax1ID)
                              .InColumnValue("invoice_tax2_id", invoiceItem.InvoiceTax2ID)
                              .InColumnValue("currency", String.Empty)
                              .InColumnValue("create_on", DateTime.UtcNow)
                              .InColumnValue("create_by", SecurityContext.CurrentAccount.ID)
                              .InColumnValue("last_modifed_on", DateTime.UtcNow)
                              .InColumnValue("last_modifed_by", SecurityContext.CurrentAccount.ID)
                              .Identity(1, 0, true));

                invoiceItem.CreateOn =  DateTime.UtcNow;
                invoiceItem.LastModifedOn = invoiceItem.CreateOn;
                invoiceItem.CreateBy = SecurityContext.CurrentAccount.ID;
                invoiceItem.LastModifedBy = invoiceItem.CreateBy;
            }
            else
            {

                var oldInvoiceItem = db.ExecuteList(GetInvoiceItemSqlQuery(Exp.Eq("id", invoiceItem.ID)))
                    .ConvertAll(ToInvoiceItem)
                    .FirstOrDefault();

                CRMSecurity.DemandEdit(oldInvoiceItem);

                db.ExecuteNonQuery(
                    Update("crm_invoice_item")
                        .Set("title", invoiceItem.Title)
                        .Set("description", invoiceItem.Description)
                        .Set("stock_keeping_unit", invoiceItem.StockKeepingUnit)
                        .Set("price", invoiceItem.Price)
                        .Set("quantity", invoiceItem.Quantity)
                        .Set("stock_quantity", invoiceItem.StockQuantity)
                        .Set("track_inventory", invoiceItem.TrackInventory)
                        .Set("invoice_tax1_id", invoiceItem.InvoiceTax1ID)
                        .Set("invoice_tax2_id", invoiceItem.InvoiceTax2ID)
                        .Set("currency", String.Empty)
                        .Set("last_modifed_on", DateTime.UtcNow)
                        .Set("last_modifed_by", SecurityContext.CurrentAccount.ID)
                        .Where(Exp.Eq("id", invoiceItem.ID)));

                invoiceItem.LastModifedOn = DateTime.UtcNow;
                invoiceItem.LastModifedBy = SecurityContext.CurrentAccount.ID;
            }

            return invoiceItem;
        }
Пример #4
0
        public InvoiceItemWrapper(InvoiceItem invoiceItem)
            : base(invoiceItem.ID)
        {
            Title = invoiceItem.Title;
            StockKeepingUnit = invoiceItem.StockKeepingUnit;
            Description = invoiceItem.Description;
            Price = invoiceItem.Price;
            Quantity = invoiceItem.Quantity;
            StockQuantity = invoiceItem.StockQuantity;
            TrackInvenory = invoiceItem.TrackInventory;

            CreateOn = (ApiDateTime)invoiceItem.CreateOn;
            CreateBy = EmployeeWraper.Get(invoiceItem.CreateBy);
            Currency = !String.IsNullOrEmpty(invoiceItem.Currency) ?
                new CurrencyInfoWrapper(CurrencyProvider.Get(invoiceItem.Currency)) :
                new CurrencyInfoWrapper(Global.TenantSettings.DefaultCurrency);
            CanEdit = CRMSecurity.CanEdit(invoiceItem);
            CanDelete = CRMSecurity.CanDelete(invoiceItem);
        }
Пример #5
0
 public static string GetJson(InvoiceItem invoiceItem) {
     return invoiceItem == null ?
             string.Empty :
             JsonConvert.SerializeObject(new
             {
                 id = invoiceItem.ID,
                 title = invoiceItem.Title,
                 description = invoiceItem.Description
             });
 }
Пример #6
0
 public static void DemandEdit(InvoiceItem invoiceItem)
 {
     if (!CanEdit(invoiceItem)) throw CreateSecurityException();
 }
Пример #7
0
 public static void DemandDelete(InvoiceItem invoiceItem)
 {
     if (!CanDelete(invoiceItem)) throw CreateSecurityException();
 }
Пример #8
0
 public static Dictionary<Guid, string> GetAccessSubjectTo(InvoiceItem invoiceItem)
 {
     return GetAccessSubjectTo((ISecurityObjectId)invoiceItem);
 }
Пример #9
0
 public static List<Guid> GetAccessSubjectGuidsTo(InvoiceItem invoiceItem)
 {
     return GetAccessSubjectGuidsTo((ISecurityObjectId)invoiceItem);
 }
Пример #10
0
 public static void MakePublic(InvoiceItem invoiceItem)
 {
     MakePublic((ISecurityObjectId)invoiceItem);
 }
Пример #11
0
 public static bool IsPrivate(InvoiceItem invoiceItem)
 {
     return IsPrivate((ISecurityObjectId)invoiceItem);
 }
Пример #12
0
 public static bool CanDelete(InvoiceItem invoiceItem)
 {
     return CanEdit(invoiceItem) && Global.DaoFactory.GetInvoiceItemDao().CanDelete(invoiceItem.ID);
 }
Пример #13
0
 public static bool CanEdit(InvoiceItem invoiceItem)
 {
     return IsAdmin;
 }
Пример #14
0
 public static void SetAccessTo(InvoiceItem invoiceItem, List<Guid> subjectID)
 {
     SetAccessTo((ISecurityObjectId)invoiceItem, subjectID);
 }
Пример #15
0
        private InvoiceItemWrapper ToInvoiceItemWrapper(InvoiceItem invoiceItem)
        {
            var result = new InvoiceItemWrapper(invoiceItem);

            if (invoiceItem.InvoiceTax1ID > 0)
            {
                result.InvoiceTax1 = ToInvoiceTaxWrapper(DaoFactory.GetInvoiceTaxDao().GetByID(invoiceItem.InvoiceTax1ID));
            }
            if (invoiceItem.InvoiceTax2ID > 0)
            {
                result.InvoiceTax2 = ToInvoiceTaxWrapper(DaoFactory.GetInvoiceTaxDao().GetByID(invoiceItem.InvoiceTax2ID));
            }

            return result;
        }
Пример #16
0
        public InvoiceItemWrapper UpdateInvoiceItem(int id,
                                                    string title,
                                                    string description,
                                                    decimal price,
                                                    string sku,
                                                    int quantity,
                                                    int stockQuantity,
                                                    bool trackInventory,
                                                    int invoiceTax1id,
                                                    int invoiceTax2id)
        {
            if (!CRMSecurity.IsAdmin) {
                throw CRMSecurity.CreateSecurityException();
            }

            if (id <= 0 || String.IsNullOrEmpty(title) || price == 0) throw new ArgumentException();

            if (!DaoFactory.GetInvoiceItemDao().IsExist(id)) throw new ItemNotFoundException();

            var invoiceItem = new InvoiceItem
                {
                    ID = id,
                    Title = title,
                    Description = description,
                    Price = price,
                    StockKeepingUnit = sku,
                    Quantity = quantity,
                    StockQuantity = stockQuantity,
                    TrackInventory = trackInventory,
                    InvoiceTax1ID = invoiceTax1id,
                    InvoiceTax2ID = invoiceTax2id
                };

            invoiceItem = DaoFactory.GetInvoiceItemDao().SaveOrUpdateInvoiceItem(invoiceItem);
            MessageService.Send(Request, MessageAction.InvoiceItemUpdated, invoiceItem.Title);

            return ToInvoiceItemWrapper(invoiceItem);
        }