Ejemplo n.º 1
0
        public long Save(DateTime valueDate, string referenceNumber, string data, int costCenterId, string attachmentsJSON)
        {
            Collection <JournalDetail> details = GetJournalDetailCollection(data);

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

            foreach (JournalDetail 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.");
            }

            int  officeId = CurrentUser.GetSignInView().OfficeId.ToInt();
            int  userId   = CurrentUser.GetSignInView().UserId.ToInt();
            long loginId  = CurrentUser.GetSignInView().LoginId.ToLong();

            return(Transaction.Add(valueDate, officeId, userId, loginId, costCenterId, referenceNumber, details, attachments));
        }
Ejemplo n.º 2
0
        public decimal GetCashRepositoryBalance(int cashRepositoryId, string currencyCode)
        {
            if (string.IsNullOrWhiteSpace(currencyCode))
            {
                return(CashRepositories.GetBalance(AppUsers.GetCurrentUserDB(), cashRepositoryId));
            }

            return(CashRepositories.GetBalance(AppUsers.GetCurrentUserDB(), cashRepositoryId, currencyCode));
        }
Ejemplo n.º 3
0
        public static async Task <long> PostAsync(string tenant, TransactionPosting model, LoginView meta)
        {
            foreach (var item in model.Details)
            {
                if (item.Debit > 0 && item.Credit > 0)
                {
                    throw new InvalidOperationException(I18N.InvalidData);
                }

                if (item.Debit == 0 && item.Credit == 0)
                {
                    throw new InvalidOperationException(I18N.InvalidData);
                }

                if (item.Credit < 0 || item.Debit < 0)
                {
                    throw new InvalidOperationException(I18N.InvalidData);
                }

                if (item.Credit > 0)
                {
                    if (await Accounts.IsCashAccountAsync(tenant, item.AccountNumber).ConfigureAwait(true))
                    {
                        if (await CashRepositories.GetBalanceAsync(tenant, item.CashRepositoryCode, item.CurrencyCode).ConfigureAwait(true) < item.Credit)
                        {
                            throw new InvalidOperationException(I18N.InsufficientBalanceInCashRepository);
                        }
                    }
                }
            }

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

            if (drTotal != crTotal)
            {
                throw new InvalidOperationException(I18N.ReferencingSidesNotEqual);
            }

            int decimalPlaces = CultureManager.GetCurrencyDecimalPlaces();

            if ((from detail in model.Details
                 where
                 decimal.Round(detail.Credit * detail.ExchangeRate, decimalPlaces) !=
                 decimal.Round(detail.LocalCurrencyCredit, decimalPlaces) ||
                 decimal.Round(detail.Debit * detail.ExchangeRate, decimalPlaces) !=
                 decimal.Round(detail.LocalCurrencyDebit, decimalPlaces)
                 select detail).Any())
            {
                throw new InvalidOperationException(I18N.ReferencingSidesNotEqual);
            }


            long tranId = await TransactionPostings.AddAsync(tenant, meta, model).ConfigureAwait(true);

            return(tranId);
        }
Ejemplo n.º 4
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));
        }
Ejemplo n.º 5
0
        public Collection <ListItem> GetCashRepositories()
        {
            Collection <ListItem> values = new Collection <ListItem>();

            int officeId = CurrentUser.GetSignInView().OfficeId.ToInt();

            foreach (CashRepository cashRepository in CashRepositories.GetCashRepositories(officeId))
            {
                values.Add(new ListItem(cashRepository.CashRepositoryName, cashRepository.CashRepositoryId.ToString(CultureInfo.InvariantCulture)));
            }
            return(values);
        }
Ejemplo n.º 6
0
        public Collection <ListItem> GetCashRepositories()
        {
            Collection <ListItem> values = new Collection <ListItem>();

            int officeId = SessionHelper.GetOfficeId();

            foreach (CashRepository cashRepository in CashRepositories.GetCashRepositories(officeId))
            {
                values.Add(new ListItem(cashRepository.CashRepositoryName, cashRepository.CashRepositoryId.ToString(CultureInfo.InvariantCulture)));
            }
            return(values);
        }
Ejemplo n.º 7
0
        public Collection <ListItem> GetCashRepositoriesByAccountNumber(string accountNumber)
        {
            Collection <ListItem> values = new Collection <ListItem>();

            if (AccountHelper.IsCashAccount(accountNumber))
            {
                int officeId = CurrentUser.GetSignInView().OfficeId.ToInt();
                foreach (CashRepository cashRepository in CashRepositories.GetCashRepositories(officeId))
                {
                    values.Add(new ListItem(cashRepository.CashRepositoryName, cashRepository.CashRepositoryCode));
                }
            }

            return(values);
        }
Ejemplo n.º 8
0
        public Collection <ListItem> GetCashRepositories()
        {
            Collection <ListItem> values = new Collection <ListItem>();

            using (DataTable table = CashRepositories.GetCashRepositoryDataTable())
            {
                string displayField = ConfigurationHelper.GetDbParameter("CashRepositoryDisplayField");
                table.Columns.Add("cash_repository", typeof(string), displayField);

                foreach (DataRow dr in table.Rows)
                {
                    values.Add(new ListItem(dr["cash_repository"].ToString(), dr["cash_repository_id"].ToString()));
                }
            }
            return(values);
        }
Ejemplo n.º 9
0
        public bool HasBalance(string cashRepositoryCode, string currencyCode, decimal credit)
        {
            if (credit.Equals(0))
            {
                return(true);
            }

            if (credit < 0)
            {
                throw new MixERPException(Warnings.NegativeValueSupplied);
            }

            decimal balance = CashRepositories.GetBalance(AppUsers.GetCurrentUserDB(), cashRepositoryCode, currencyCode);

            if (balance > credit)
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 10
0
        public bool HasBalance(string cashRepositoryCode, string currencyCode, decimal credit)
        {
            if (credit.Equals(0))
            {
                return(true);
            }

            if (credit < 0)
            {
                throw new InvalidOperationException("Negetive value supplied.");
            }

            decimal balance = CashRepositories.GetBalance(cashRepositoryCode, currencyCode);

            if (balance > credit)
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 11
0
        public Collection <ListItem> GetCashRepositoriesByAccountCode(string accountCode)
        {
            Collection <ListItem> values = new Collection <ListItem>();

            if (Accounts.IsCashAccount(accountCode))
            {
                int officeId = SessionHelper.GetOfficeId();
                using (DataTable table = CashRepositories.GetCashRepositoryDataTable(officeId))
                {
                    string displayField = ConfigurationHelper.GetDbParameter("CashRepositoryDisplayField");
                    table.Columns.Add("cash_repository", typeof(string), displayField);

                    foreach (DataRow dr in table.Rows)
                    {
                        values.Add(new ListItem(dr["cash_repository"].ToString(), dr["cash_repository_code"].ToString()));
                    }
                }
            }

            return(values);
        }
Ejemplo n.º 12
0
 public bool CashRepositoryCodeExists(string cashRepositoryCode)
 {
     return(CashRepositories.CashRepositoryCodeExists(AppUsers.GetCurrentUserDB(), cashRepositoryCode));
 }
Ejemplo n.º 13
0
 public bool CashRepositoryCodeExists(string cashRepositoryCode)
 {
     return(CashRepositories.CashRepositoryCodeExists(cashRepositoryCode));
 }
Ejemplo n.º 14
0
        public async Task <ActionResult> PostAsync(TransactionPosting model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.InvalidModelState(this.ModelState));
            }



            foreach (var item in model.Details)
            {
                if (item.Debit > 0 && item.Credit > 0)
                {
                    throw new InvalidOperationException(I18N.InvalidData);
                }

                if (item.Debit == 0 && item.Credit == 0)
                {
                    throw new InvalidOperationException(I18N.InvalidData);
                }

                if (item.Credit < 0 || item.Debit < 0)
                {
                    throw new InvalidOperationException(I18N.InvalidData);
                }

                if (item.Credit > 0)
                {
                    if (await Accounts.IsCashAccountAsync(this.Tenant, item.AccountNumber).ConfigureAwait(true))
                    {
                        if (
                            await CashRepositories.GetBalanceAsync(this.Tenant, item.CashRepositoryCode,
                                                                   item.CurrencyCode).ConfigureAwait(true) < item.Credit)
                        {
                            throw new InvalidOperationException(I18N.InsufficientBalanceInCashRepository);
                        }
                    }
                }
            }

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

            if (drTotal != crTotal)
            {
                throw new InvalidOperationException(I18N.ReferencingSidesNotEqual);
            }

            int decimalPlaces = CultureManager.GetCurrencyDecimalPlaces();

            if ((from detail in model.Details
                 where
                 decimal.Round(detail.Credit * detail.ExchangeRate, decimalPlaces) !=
                 decimal.Round(detail.LocalCurrencyCredit, decimalPlaces) ||
                 decimal.Round(detail.Debit * detail.ExchangeRate, decimalPlaces) !=
                 decimal.Round(detail.LocalCurrencyDebit, decimalPlaces)
                 select detail).Any())
            {
                throw new InvalidOperationException(I18N.ReferencingSidesNotEqual);
            }

            var user = await AppUsers.GetCurrentAsync().ConfigureAwait(true);

            try
            {
                long tranId = await TransacitonPostings.AddAsync(this.Tenant, user, model).ConfigureAwait(true);

                return(this.Ok(tranId));
            }
            catch (Exception ex)
            {
                return(this.Failed(ex.Message, HttpStatusCode.InternalServerError));
            }
        }