示例#1
0
        public long Save(long tranId, DateTime valueDate, int storeId, string partyCode, int priceTypeId, string referenceNumber, string data, string statementReference, string attachmentsJSON)
        {
            if (!StockTransaction.IsValidStockTransactionByTransactionMasterId(tranId))
            {
                throw new InvalidOperationException(Resources.Warnings.InvalidStockTransaction);
            }

            if (!StockTransaction.IsValidPartyByTransactionMasterId(tranId, partyCode))
            {
                throw new InvalidOperationException(Resources.Warnings.InvalidParty);
            }

            Collection <StockDetail> details = CollectionHelper.GetStockMasterDetailCollection(data, storeId);

            if (!this.ValidateDetails(details, tranId))
            {
                return(0);
            }

            Collection <Attachment> attachments = CollectionHelper.GetAttachmentCollection(attachmentsJSON);

            int  officeId = CurrentSession.GetOfficeId();
            int  userId   = CurrentSession.GetUserId();
            long loginId  = CurrentSession.GetLogOnId();

            return(Data.Transactions.Return.PostTransaction(tranId, valueDate, officeId, userId, loginId, storeId, partyCode, priceTypeId, referenceNumber, statementReference, details, attachments));
        }
示例#2
0
        public bool Save(string book, long id, string attachmentsJSON)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(book))
                {
                    throw new ArgumentNullException("book");
                }

                if (id <= 0)
                {
                    throw new ArgumentNullException("id");
                }

                if (string.IsNullOrWhiteSpace(attachmentsJSON))
                {
                    throw new ArgumentNullException("attachmentsJSON");
                }

                Collection <Attachment> attachments = CollectionHelper.GetAttachmentCollection(attachmentsJSON);
                int userId = AppUsers.GetCurrentLogin().View.UserId.ToInt();

                return(Data.Attachments.Save(AppUsers.GetCurrentUserDB(), userId, book, id, attachments));
            }
            catch (Exception ex)
            {
                Log.Warning("Could not save attachment. {Exception}", ex);
                throw;
            }
        }
示例#3
0
        public long Save(DateTime valueDate, string referenceNumber, string data, int costCenterId, string attachmentsJSON)
        {
            Collection <JournalDetailsModel> details = CollectionHelper.GetJournalDetailCollection(data);

            JavaScriptSerializer js = new JavaScriptSerializer();
            Collection <PostgresqlAttachmentModel> attachments = js.Deserialize <Collection <PostgresqlAttachmentModel> >(attachmentsJSON);

            foreach (JournalDetailsModel model in details)
            {
                if (model.Debit > 0 && model.Credit > 0)
                {
                    throw new InvalidOperationException("Invalid data");
                }

                if (model.Debit == 0 && model.Credit == 0)
                {
                    throw new InvalidOperationException("Invalid data");
                }

                if (model.Credit < 0 || model.Debit < 0)
                {
                    throw new InvalidOperationException("Invalid data");
                }

                if (!AccountHelper.AccountNumberExists(model.AccountNumber))
                {
                    throw new InvalidOperationException("Invalid account " + model.AccountNumber);
                }

                if (model.Credit > 0)
                {
                    if (AccountHelper.IsCashAccount(model.AccountNumber))
                    {
                        if (!CashRepositories.CashRepositoryCodeExists(model.CashRepositoryCode))
                        {
                            throw new InvalidOperationException("Invalid cash repository " + model.CashRepositoryCode);
                        }

                        if (CashRepositories.GetBalance(model.CashRepositoryCode, model.CurrencyCode) < model.Credit)
                        {
                            throw new InvalidOperationException("Insufficient balance in cash repository.");
                        }
                    }
                }
            }

            decimal drTotal = (from detail in details select detail.LocalCurrencyDebit).Sum();
            decimal crTotal = (from detail in details select detail.LocalCurrencyCredit).Sum();

            if (drTotal != crTotal)
            {
                throw new InvalidOperationException("Referencing sides are not equal.");
            }

            return(Transaction.Add(valueDate, referenceNumber, costCenterId, details, attachments));
        }
示例#4
0
        public long Save(DateTime valueDate, int storeId, string partyCode, int priceTypeId, string referenceNumber,
                         string data, string statementReference, string transactionIds, string attachmentsJSON, bool nonTaxable,
                         int salespersonId, int shipperId, string shippingAddressCode)
        {
            try
            {
                Collection <StockDetail> details = CollectionHelper.GetStockMasterDetailCollection(data, storeId);
                Collection <long>        tranIds = new Collection <long>();

                Collection <Attachment> attachments = CollectionHelper.GetAttachmentCollection(attachmentsJSON);

                if (!string.IsNullOrWhiteSpace(transactionIds))
                {
                    foreach (string transactionId in transactionIds.Split(','))
                    {
                        tranIds.Add(Conversion.TryCastInteger(transactionId));
                    }
                }

                int  officeId      = AppUsers.GetCurrent().View.OfficeId.ToInt();
                int  userId        = AppUsers.GetCurrent().View.UserId.ToInt();
                long loginId       = AppUsers.GetCurrent().View.LoginId.ToLong();
                int  validDuration = AppUsers.GetCurrent().View.SalesQuotationValidDuration.ToInt();

                long tranId = Data.Transactions.Quotation.Add(AppUsers.GetCurrentUserDB(), officeId, userId, loginId,
                                                              valueDate, partyCode, priceTypeId, details, referenceNumber, statementReference, tranIds,
                                                              attachments, nonTaxable, salespersonId, shipperId, shippingAddressCode, storeId);
                string token = Data.Transactions.Quotation.AddValidation(AppUsers.GetCurrentUserDB(), validDuration,
                                                                         tranId);

                if (tranId > 0)
                {
                    this.CreateEmail(tranId, partyCode, token);
                }

                return(tranId);
            }
            catch (Exception ex)
            {
                Log.Warning("Could not save sales quotation entry. {Exception}", ex);
                throw;
            }
        }
示例#5
0
        public bool Save(string book, long id, string attachmentsJSON)
        {
            if (string.IsNullOrWhiteSpace(book))
            {
                throw new ArgumentNullException("book");
            }

            if (id <= 0)
            {
                throw new ArgumentNullException("id");
            }

            if (string.IsNullOrWhiteSpace(attachmentsJSON))
            {
                throw new ArgumentNullException("attachmentsJSON");
            }

            Collection <Attachment> attachments = CollectionHelper.GetAttachmentCollection(attachmentsJSON);
            int userId = CurrentSession.GetUserId();

            return(Data.Attachments.Save(userId, book, id, attachments));
        }