public IActionResult Remove(string id)
        {
            var result = "";

            try
            {
                var poco = _customerLogic.GetSingleById(Convert.ToInt32(id));
                if (poco != null)
                {
                    _chartOfAccountLogic = new Lms_ChartOfAccountLogic(_cache, new EntityFrameworkGenericRepository <Lms_ChartOfAccountPoco>(_dbContext));
                    var accPoco = _chartOfAccountLogic.GetSingleById(poco.AccountId);
                    _chartOfAccountLogic.Remove(accPoco);

                    _customerAddressMappingLogic = new Lms_CustomerAddressMappingLogic(_cache, new EntityFrameworkGenericRepository <Lms_CustomerAddressMappingPoco>(_dbContext));
                    var mappingAddresses = _customerAddressMappingLogic.GetList().Where(c => c.CustomerId == poco.Id).ToList();

                    if (mappingAddresses.Count > 0)
                    {
                        foreach (var item in mappingAddresses)
                        {
                            _customerAddressMappingLogic.Remove(item);
                        }
                    }

                    _customerLogic.Remove(poco);
                }

                result = "Success";
            }
            catch (Exception ex)
            {
            }
            return(Json(result));
        }
Ejemplo n.º 2
0
        private bool DeleteCustomerById(int customerId)
        {
            bool isDeleted = false;

            try
            {
                var poco = _customerLogic.GetSingleById(Convert.ToInt32(customerId));
                if (poco != null)
                {
                    _chartOfAccountLogic = new Lms_ChartOfAccountLogic(_cache, new EntityFrameworkGenericRepository <Lms_ChartOfAccountPoco>(_dbContext));
                    var accPoco = _chartOfAccountLogic.GetSingleById(poco.AccountId);
                    _chartOfAccountLogic.Remove(accPoco);

                    _customerAddressMappingLogic = new Lms_CustomerAddressMappingLogic(_cache, new EntityFrameworkGenericRepository <Lms_CustomerAddressMappingPoco>(_dbContext));
                    var mappingAddresses = _customerAddressMappingLogic.GetList().Where(c => c.CustomerId == poco.Id).ToList();

                    if (mappingAddresses.Count > 0)
                    {
                        foreach (var item in mappingAddresses)
                        {
                            _customerAddressMappingLogic.Remove(item);
                        }
                    }
                    _customerLogic.Remove(poco);
                    isDeleted = true;
                }
            }
            catch (Exception ex)
            {
                //
            }
            return(isDeleted);
        }
Ejemplo n.º 3
0
        public IActionResult Remove(string id)
        {
            var result = "";

            try
            {
                var poco = _customerLogic.GetSingleById(Convert.ToInt32(id));
                if (poco != null)
                {
                    _chartOfAccountLogic = new Lms_ChartOfAccountLogic(_cache, new EntityFrameworkGenericRepository <Lms_ChartOfAccountPoco>(_dbContext));
                    var accPoco = _chartOfAccountLogic.GetSingleById(poco.AccountId);
                    _chartOfAccountLogic.Remove(accPoco);
                }

                _customerLogic.Remove(poco);

                result = "Success";
            }
            catch (Exception ex)
            {
            }
            return(Json(result));
        }
Ejemplo n.º 4
0
        /// <summary>
        ///  Should be able to make single debit, multiple credit and single credit multiple debit entries. Therefore debit and credit info are passed as objects
        /// </summary>
        /// <param name="debitAccountInfo"></param>
        /// <param name="creditAccountInfo"></param>
        /// <param name="transactionAmount"></param>
        /// <param name="transactionDate"></param>
        /// <param name="valueDate"></param>
        /// <param name="transactionRemarks"></param>
        /// <returns></returns>
        public int MakeTransaction(List <TransactionModel> debitAccountInfo, List <TransactionModel> creditAccountInfo, decimal transactionAmount, DateTime transactionDate, DateTime valueDate, string transactionRemarks)
        {
            var transactionId = _transactionDetailLogic.GetMaxId() + 1;

            Lms_TransactionDetailPoco txnDetail = new Lms_TransactionDetailPoco();

            txnDetail.Id = transactionId;
            txnDetail.TransactionAmount = transactionAmount;
            txnDetail.TransactionDate   = transactionDate;
            txnDetail.ValueDate         = valueDate;
            txnDetail.Remarks           = transactionRemarks;
            _transactionDetailLogic.Add(txnDetail);

            Lms_TransactionPoco _transactionPoco = new Lms_TransactionPoco();

            if (debitAccountInfo.Count == 1)
            {
                //Add Debit side
                _transactionPoco                   = new Lms_TransactionPoco();
                _transactionPoco.Id                = transactionId;
                _transactionPoco.SerialNo          = 1;
                _transactionPoco.AccountId         = debitAccountInfo.FirstOrDefault().AccountId;
                _transactionPoco.TransactionAmount = debitAccountInfo.FirstOrDefault().TxnAmount;
                _transactionPoco.Remarks           = transactionRemarks;
                if (_transactionPoco.TransactionAmount > 0)
                {
                    _transactionLogic.Add(_transactionPoco);
                    var debitAccount = _chartOfAccountLogic.GetSingleById(_transactionPoco.AccountId);
                    debitAccount.CurrentBalance = debitAccount.CurrentBalance + _transactionPoco.TransactionAmount;
                    _chartOfAccountLogic.Update(debitAccount);
                }

                //Add Credit side
                var serialNo = 2;
                for (int i = 0; i < creditAccountInfo.Count; i++)
                {
                    _transactionPoco                   = new Lms_TransactionPoco();
                    _transactionPoco.Id                = transactionId;
                    _transactionPoco.SerialNo          = serialNo + i;
                    _transactionPoco.AccountId         = creditAccountInfo[i].AccountId;
                    _transactionPoco.TransactionAmount = (-1) * creditAccountInfo[i].TxnAmount;
                    _transactionPoco.Remarks           = transactionRemarks;
                    if (_transactionPoco.TransactionAmount < 0)
                    {
                        _transactionLogic.Add(_transactionPoco);
                        var creditAccount = _chartOfAccountLogic.GetSingleById(_transactionPoco.AccountId);
                        creditAccount.CurrentBalance = creditAccount.CurrentBalance + _transactionPoco.TransactionAmount;
                        _chartOfAccountLogic.Update(creditAccount);
                    }
                }
            }

            else if (creditAccountInfo.Count == 1)
            {
                //Add Credit side
                _transactionPoco                   = new Lms_TransactionPoco();
                _transactionPoco.Id                = transactionId;
                _transactionPoco.SerialNo          = 1;
                _transactionPoco.AccountId         = creditAccountInfo.FirstOrDefault().AccountId;
                _transactionPoco.TransactionAmount = (-1) * creditAccountInfo.FirstOrDefault().TxnAmount;
                _transactionPoco.Remarks           = transactionRemarks;
                if (_transactionPoco.TransactionAmount < 0)
                {
                    _transactionLogic.Add(_transactionPoco);
                    var creditAccount = _chartOfAccountLogic.GetSingleById(_transactionPoco.AccountId);
                    creditAccount.CurrentBalance = creditAccount.CurrentBalance + _transactionPoco.TransactionAmount;
                    _chartOfAccountLogic.Update(creditAccount);
                }
                //Add Debit side
                var serialNo = 2;
                for (int i = 0; i < debitAccountInfo.Count; i++)
                {
                    _transactionPoco                   = new Lms_TransactionPoco();
                    _transactionPoco.Id                = transactionId;
                    _transactionPoco.SerialNo          = serialNo + i;
                    _transactionPoco.AccountId         = debitAccountInfo[i].AccountId;
                    _transactionPoco.TransactionAmount = debitAccountInfo[i].TxnAmount;
                    _transactionPoco.Remarks           = transactionRemarks;
                    if (_transactionPoco.TransactionAmount > 0)
                    {
                        _transactionLogic.Add(_transactionPoco);

                        var debitAccount = _chartOfAccountLogic.GetSingleById(_transactionPoco.AccountId);
                        debitAccount.CurrentBalance = debitAccount.CurrentBalance + _transactionPoco.TransactionAmount;
                        _chartOfAccountLogic.Update(debitAccount);
                    }
                }
            }

            return(transactionId);
        }
        public IActionResult Update([FromBody] dynamic customerData)
        {
            ValidateSession();
            var result = "";

            try
            {
                if (customerData != null)
                {
                    Lms_CustomerPoco       customerPoco    = JsonConvert.DeserializeObject <Lms_CustomerPoco>(JsonConvert.SerializeObject(customerData[0]));
                    CustomerAddressMapping customerAddress = JsonConvert.DeserializeObject <CustomerAddressMapping>(JsonConvert.SerializeObject(customerData[1]));
                    _configurationLogic  = new Lms_ConfigurationLogic(_cache, new EntityFrameworkGenericRepository <Lms_ConfigurationPoco>(_dbContext));
                    _chartOfAccountLogic = new Lms_ChartOfAccountLogic(_cache, new EntityFrameworkGenericRepository <Lms_ChartOfAccountPoco>(_dbContext));
                    var jAddressObject           = (JObject)customerData[1];
                    var shippingAddressMappingId = Convert.ToString(jAddressObject.SelectToken("shippingAddressMappingId"));
                    var billingAddressMappingId  = Convert.ToString(jAddressObject.SelectToken("billingAddressMappingId"));
                    //using (var scope = new TransactionScope())
                    //{
                    if (customerPoco.Id > 0)
                    {
                        var customer = _customerLogic.GetSingleById(customerPoco.Id);
                        customer.CustomerName            = customerPoco.CustomerName;
                        customer.DiscountPercentage      = customerPoco.DiscountPercentage;
                        customer.FuelSurChargePercentage = customerPoco.FuelSurChargePercentage > 0 ? customerPoco.FuelSurChargePercentage : null;
                        customer.InvoiceDueDays          = customerPoco.InvoiceDueDays;
                        customer.IsGstApplicable         = customerPoco.IsGstApplicable;
                        customer.IsActive = customerPoco.IsActive;

                        var accountInfo = _chartOfAccountLogic.GetSingleById(customer.AccountId);
                        accountInfo.AccountName = customerPoco.CustomerName;

                        _chartOfAccountLogic.Update(accountInfo);
                        result = _customerLogic.Update(customer).Id.ToString();

                        if (customerAddress != null)
                        {
                            customerAddress.CustomerId = customerPoco.Id;
                            customerAddress.IsDefault  = true;
                            _addressLogic = new Lms_AddressLogic(_cache, new EntityFrameworkGenericRepository <Lms_AddressPoco>(_dbContext));
                            var addressList = _addressLogic.GetList();

                            _customerAddressMappingLogic = new Lms_CustomerAddressMappingLogic(_cache, new EntityFrameworkGenericRepository <Lms_CustomerAddressMappingPoco>(_dbContext));
                            var customerAddressList = _customerAddressMappingLogic.GetList().Where(c => c.CustomerId == customerAddress.CustomerId);

                            int addressId       = 0;
                            var existingAddress = addressList.Where(c => c.UnitNumber == customerAddress.UnitNumber && c.AddressLine == customerAddress.AddressLine && c.CityId == customerAddress.CityId).ToList().FirstOrDefault();
                            if (existingAddress != null)
                            {
                                existingAddress.ProvinceId         = customerAddress.ProvinceId;
                                existingAddress.CountryId          = customerAddress.CountryId;
                                existingAddress.PostCode           = customerAddress.PostCode;
                                existingAddress.PrimaryPhoneNumber = customerAddress.PrimaryPhoneNumber;
                                existingAddress.Fax               = customerAddress.Fax;
                                existingAddress.EmailAddress1     = customerAddress.EmailAddress1;
                                existingAddress.EmailAddress2     = customerAddress.EmailAddress1;
                                existingAddress.ContactPersonName = customerAddress.ContactPersonName;

                                addressId = _addressLogic.Update(existingAddress).Id;
                            }
                            else
                            {
                                Lms_AddressPoco addressPoco = new Lms_AddressPoco();
                                addressPoco.UnitNumber         = customerAddress.UnitNumber;
                                addressPoco.AddressLine        = customerAddress.AddressLine;
                                addressPoco.CityId             = customerAddress.CityId;
                                addressPoco.ProvinceId         = customerAddress.ProvinceId;
                                addressPoco.CountryId          = customerAddress.CountryId;
                                addressPoco.PostCode           = customerAddress.PostCode;
                                addressPoco.PrimaryPhoneNumber = customerAddress.PrimaryPhoneNumber;
                                addressPoco.Fax               = customerAddress.Fax;
                                addressPoco.EmailAddress1     = customerAddress.EmailAddress1;
                                addressPoco.EmailAddress2     = customerAddress.EmailAddress1;
                                addressPoco.ContactPersonName = customerAddress.ContactPersonName;

                                addressId = _addressLogic.Add(addressPoco).Id;
                            }

                            // This will ensure only one address is set as default address for the same type
                            var typeWiseAddresses = new List <Lms_CustomerAddressMappingPoco>();
                            if (customerAddress.IsDefault)
                            {
                                typeWiseAddresses = customerAddressList.Where(c => c.CustomerId == customerAddress.CustomerId && c.AddressTypeId == customerAddress.AddressTypeId).ToList();
                                if (typeWiseAddresses.Count > 0)
                                {
                                    foreach (var item in typeWiseAddresses)
                                    {
                                        item.IsDefault = false;
                                        _customerAddressMappingLogic.Update(item);
                                    }
                                }
                            }

                            var addressMappingList = _customerAddressMappingLogic.GetList();
                            if (customerAddress.AddressTypeId == 0)
                            {
                                Lms_CustomerAddressMappingPoco customerAddressMappingPoco = new Lms_CustomerAddressMappingPoco();

                                if (billingAddressMappingId != "")
                                {
                                    customerAddressMappingPoco = addressMappingList.Where(c => c.Id == Convert.ToInt32(billingAddressMappingId)).FirstOrDefault();
                                    customerAddressMappingPoco.AddressTypeId = (byte)Enum_AddressType.Billing;
                                    customerAddressMappingPoco.AddressId     = addressId;
                                    customerAddressMappingPoco.IsDefault     = true;
                                    _customerAddressMappingLogic.Update(customerAddressMappingPoco);
                                }
                                else
                                {
                                    customerAddressMappingPoco               = new Lms_CustomerAddressMappingPoco();
                                    customerAddressMappingPoco.CustomerId    = customerAddress.CustomerId;
                                    customerAddressMappingPoco.AddressId     = addressId;
                                    customerAddressMappingPoco.AddressTypeId = (byte)Enum_AddressType.Billing;
                                    customerAddressMappingPoco.IsDefault     = true;
                                    _customerAddressMappingLogic.Add(customerAddressMappingPoco);
                                }

                                if (shippingAddressMappingId != "")
                                {
                                    customerAddressMappingPoco = addressMappingList.Where(c => c.Id == Convert.ToInt32(shippingAddressMappingId)).FirstOrDefault();
                                    customerAddressMappingPoco.AddressTypeId = (byte)Enum_AddressType.Shipping;
                                    customerAddressMappingPoco.AddressId     = addressId;
                                    customerAddressMappingPoco.IsDefault     = true;
                                    _customerAddressMappingLogic.Update(customerAddressMappingPoco);
                                }
                                else
                                {
                                    customerAddressMappingPoco               = new Lms_CustomerAddressMappingPoco();
                                    customerAddressMappingPoco.CustomerId    = customerAddress.CustomerId;
                                    customerAddressMappingPoco.AddressId     = addressId;
                                    customerAddressMappingPoco.AddressTypeId = (byte)Enum_AddressType.Shipping;
                                    customerAddressMappingPoco.IsDefault     = true;
                                    _customerAddressMappingLogic.Add(customerAddressMappingPoco);
                                }
                            }
                            else
                            {
                                Lms_CustomerAddressMappingPoco customerAddressMappingPoco = new Lms_CustomerAddressMappingPoco();

                                if (customerAddress.AddressTypeId == 1)
                                {
                                    if (billingAddressMappingId != "")
                                    {
                                        customerAddressMappingPoco           = addressMappingList.Where(c => c.Id == Convert.ToInt32(billingAddressMappingId)).FirstOrDefault();
                                        customerAddressMappingPoco.AddressId = addressId;
                                        customerAddressMappingPoco.IsDefault = true;
                                        _customerAddressMappingLogic.Update(customerAddressMappingPoco);
                                    }
                                    else
                                    {
                                        customerAddressMappingPoco               = new Lms_CustomerAddressMappingPoco();
                                        customerAddressMappingPoco.CustomerId    = customerAddress.CustomerId;
                                        customerAddressMappingPoco.AddressId     = addressId;
                                        customerAddressMappingPoco.AddressTypeId = customerAddress.AddressTypeId;
                                        customerAddressMappingPoco.IsDefault     = true;
                                        _customerAddressMappingLogic.Add(customerAddressMappingPoco);
                                    }
                                }
                                if (customerAddress.AddressTypeId == 2)
                                {
                                    if (shippingAddressMappingId != "")
                                    {
                                        customerAddressMappingPoco           = addressMappingList.Where(c => c.Id == Convert.ToInt32(shippingAddressMappingId)).FirstOrDefault();
                                        customerAddressMappingPoco.AddressId = addressId;
                                        customerAddressMappingPoco.IsDefault = true;
                                        _customerAddressMappingLogic.Update(customerAddressMappingPoco);
                                    }
                                    else
                                    {
                                        customerAddressMappingPoco               = new Lms_CustomerAddressMappingPoco();
                                        customerAddressMappingPoco.CustomerId    = customerAddress.CustomerId;
                                        customerAddressMappingPoco.AddressId     = addressId;
                                        customerAddressMappingPoco.AddressTypeId = customerAddress.AddressTypeId;
                                        customerAddressMappingPoco.IsDefault     = true;
                                        _customerAddressMappingLogic.Add(customerAddressMappingPoco);
                                    }
                                }
                            }
                        }

                        //scope.Complete();
                    }

                    //}
                }
            }
            catch (Exception ex)
            {
            }

            return(Json(result));
        }
Ejemplo n.º 6
0
        public IActionResult Update([FromBody] dynamic customerData)
        {
            ValidateSession();
            int customerId        = 0;
            int billingAddressId  = 0;
            int shippingAddressId = 0;

            try
            {
                if (customerData != null)
                {
                    Lms_CustomerPoco customerPoco            = JsonConvert.DeserializeObject <Lms_CustomerPoco>(JsonConvert.SerializeObject(customerData[0]));
                    CustomerAddress  customerBillingAddress  = JsonConvert.DeserializeObject <CustomerAddress>(JsonConvert.SerializeObject(customerData[1]));
                    CustomerAddress  customerShippingAddress = JsonConvert.DeserializeObject <CustomerAddress>(JsonConvert.SerializeObject(customerData[2]));

                    if (customerPoco.Id < 1)
                    {
                        return(Json(""));
                    }

                    var existingCustomer = _customerLogic.GetSingleById(customerPoco.Id);
                    if (existingCustomer != null)
                    {
                        existingCustomer.CustomerName            = customerPoco.CustomerName;
                        existingCustomer.DiscountPercentage      = customerPoco.DiscountPercentage;
                        existingCustomer.FuelSurChargePercentage = customerPoco.FuelSurChargePercentage > 0 ? customerPoco.FuelSurChargePercentage : null;
                        existingCustomer.InvoiceDueDays          = customerPoco.InvoiceDueDays;
                        existingCustomer.IsGstApplicable         = customerPoco.IsGstApplicable;
                        existingCustomer.IsActive = customerPoco.IsActive;

                        var existingAccountInfo = _chartOfAccountLogic.GetSingleById(existingCustomer.AccountId);
                        existingAccountInfo.AccountName = customerPoco.CustomerName;

                        _chartOfAccountLogic.Update(existingAccountInfo);
                        customerId = _customerLogic.Update(existingCustomer).Id;
                    }

                    customerBillingAddress.CustomerId  = customerId;
                    customerShippingAddress.CustomerId = customerId;

                    billingAddressId  = AddOrGetAddress(customerBillingAddress);
                    shippingAddressId = AddOrGetAddress(customerShippingAddress);

                    DeleteExistingMappedBillingAddress(customerId);
                    if (billingAddressId > 0)
                    {
                        SetBillingShippingAddress(customerId, billingAddressId, (byte)Enum_AddressType.Billing, true);
                    }

                    DeleteExistingMappedShippingAddress(customerId, shippingAddressId);
                    MakeAllShippingAddressSecondary(customerId);
                    if (shippingAddressId > 0)
                    {
                        SetBillingShippingAddress(customerId, shippingAddressId, (byte)Enum_AddressType.Shipping, true);
                    }
                }
            }
            catch (Exception ex)
            {
            }

            return(Json(customerId.ToString()));
        }