public NewReceiptBatchViewModel()
 {
     BatchTypes = BatchTypeFunctions.GetBatchTypes();
     ReceiptBatch = new ReceiptBatch();
     ReceiptBatch.ReceiptDate = DateTime.Today;
     SelectedBatch = string.Empty;
     Popup = new InteractionRequest<PopupWindow>();
 }
示例#2
0
        public IActionResult Post([FromBody] ReceiptBatchAddDTO receiptBatch)
        {
            if (receiptBatch == null)
            {
                return(BadRequest(new ErrorViewModel
                {
                    ErrorCode = "400",
                    ErrorMessage = "Thông tin cung cấp không chính xác."
                }));
            }

            if (!ModelState.IsValid)
            {
                var errorViewModel = new ErrorViewModel
                {
                    ErrorCode    = "400",
                    ErrorMessage = ModelState.ToErrorMessages()
                };

                return(BadRequest(errorViewModel));
            }

            bool isExisting = this._receiptBatchRepository.CheckExistingCode(receiptBatch.ReceiptBatchNo);

            if (isExisting)
            {
                return(BadRequest(new ErrorViewModel
                {
                    ErrorCode = "400",
                    ErrorMessage = "Số lô phiếu thu này đã tồn tại."
                }));
            }

            var newReceiptBatch = new ReceiptBatch
            {
                ReceiptBatchNo          = receiptBatch.ReceiptBatchNo,
                ReceiptBatchDate        = receiptBatch.ReceiptBatchDate,
                DescriptionInVietNamese = receiptBatch.DescriptionInVietNamese,
                BatchStatus             = receiptBatch.BatchStatus,
                CreatedBy   = "admin",
                CreatedDate = DateTime.Now,
                UpdatedBy   = "admin",
                UpdatedDate = DateTime.Now
            };

            bool isSuccess = this._receiptBatchRepository.Insert(newReceiptBatch);

            if (isSuccess == false)
            {
                return(StatusCode(500, new ErrorViewModel
                {
                    ErrorCode = "500",
                    ErrorMessage = "Có lỗi trong quá trình cập nhật dữ liệu."
                }));
            }

            return(Ok(newReceiptBatch));
        }
        public NewReceiptBatchViewModel(int batchType)
        {
            BatchType batch;

            try
            {
                BatchTypes = BatchTypeFunctions.GetBatchTypes();
                ReceiptBatch = new ReceiptBatch();

                if (batchType == (int)ReceiptBatchType.Dishonour)
                {
                    ReceiptBatch.ReceiptDate = DateTime.Today.AddDays(-1);
                }
                else
                {
                    ReceiptBatch.ReceiptDate = DateTime.Today;
                }

                SelectedBatch = string.Empty;

                if (batchType != 0)
                {
                    batch = BatchTypes.Where(batchtype => batchtype.ID == batchType).FirstOrDefault();

                    if (batch != null)
                    {
                        BatchType = batch.ID;
                        SelectedBatch = batch.Description;
                    }
                }

                FromDate = DateTime.Today;
                ToDate = DateTime.Today;

                SaveCommand = new DelegateCommand(Save);
                CancelCommand = new DelegateCommand(Cancel);
                SearchCommand = new DelegateCommand(Search);
                InterCompanyBankSelectedCommand = new DelegateCommand<ObservableCollection<object>>(InterCompanyBankSelected);
                ReceiptSelectedCommand = new DelegateCommand<ObservableCollection<object>>(ReceiptSelected);

                UIConfirmation = new InteractionRequest<ConfirmationWindowViewModel>();
                Popup = new InteractionRequest<PopupWindow>();
            }
            catch (Exception ex)
            {
                ExceptionLogger.WriteLog(ex);
                ShowErrorMessage("Error encountered while initializing New Receipt Batch.", "Create Batch - Error");
            }
            finally
            {
                IsBusy = false;
            }
        }       
示例#4
0
 public bool Remove(ReceiptBatch receiptBatch)
 {
     try
     {
         this._context.ReceiptBatches.Remove(receiptBatch);
         int rowEffected = this._context.SaveChanges();
         return(rowEffected == 1);
     }
     catch (Exception)
     {
         return(false);
     }
 }
        private void SaveReceiptBatch()
        {
            PopupWindow popupWindow;
            AccountingParam accountingParam;
            ReceiptBatch newReceiptBatch;
            Receipt receipt = null;
            List<OpenItemReceiptAllocation> receiptAllocations = null;
            List<businessModel.DirectDebitException> DDExceptions = null;
            List<businessModel.CreditCardException> CCExceptions = null;
            IEnumerable<int> openItemIDs = null;
            OpenItemReceiptAllocation newAllocation;

            try
            {
                int contractID = 0;
                isChanged = true;
                bool isNew;

                accountingParam = SystemFunctions.GetAccountingParam();
                isNew = receiptBatch.ID == 0;

                receiptBatch.BatchStatusID = (int)ReceiptBatchStatus.Created;

                if (accountingParam.CurrentAccountingDate.HasValue)
                {
                    receiptBatch.AccountingDate = accountingParam.CurrentAccountingDate;
                    receiptBatch.BatchMonth = accountingParam.CurrentAccountingDate.Value.ToString("MMM yyyy");
                }
                else
                {
                    receiptBatch.AccountingDate = receiptBatch.ReceiptDate;
                    receiptBatch.BatchMonth = receiptBatch.ReceiptDate.ToString("MMM yyyy");
                }

                receiptBatch.CreatedByUserID = ((OperationsPrincipal)Thread.CurrentPrincipal).Identity.User.UserEntityId;

                if (receiptBatchType == ReceiptBatchType.CashCheque)
                {
                    ReceiptBatchFunctions.Save(receiptBatch);

                    if (isNew && createFromList.Where(from => from.ID == createFrom).FirstOrDefault().Description.ToLower().Trim() == ReceiptBatchCreateFrom.Import.ToString().ToLower().Trim())
                    {
                        ReturnValue = new NavigationItem() { ReceiptID = receiptBatch.ID, ReceiptText = receiptBatch.ID.ToString() + "-" + SelectedBatch, BatchStatus = (int)ReceiptBatchStatus.Created, BatchTypeID = receiptBatch.BatchTypeID };

                        IsBusy = true;
                        popupWindow = new PopupWindow(ViewAssemblies.ReceiptsViewAssembly, "CashCheque.CashReceiptExcelImport", true);
                        popupWindow.Parameters.Add(receiptBatch.ID);
                        Popup.Raise(popupWindow);
                        receiptBatch = ReceiptBatchFunctions.Get(receiptBatch.ID);
                        IsBusy = false;
                    }
                    else
                    {
                        ReturnValue = new NavigationItem() { ReceiptID = receiptBatch.ID, ReceiptText = receiptBatch.ID.ToString() + "-" + SelectedBatch, BatchStatus = (int)ReceiptBatchStatus.Created, BatchTypeID = receiptBatch.BatchTypeID };
                        Close();
                    }
                }
                else if (receiptBatchType == ReceiptBatchType.DirectDebit || receiptBatchType == ReceiptBatchType.CreditCard || receiptBatchType == ReceiptBatchType.AutoReceipts)
                {
                    if (IsDateRangeApplicable)
                    {
                        receiptAllocations = DDCCBatchFunctions.GetDDCCOpenItemsReceiptAllocation(receiptBatchType, fromDate, toDate, IsIntercompanySelected, selectedinternalCompanyBanks);

                        openItemIDs = receiptAllocations.Select(item => item.OpenItemID).Distinct();

                        if (receiptBatchType == ReceiptBatchType.DirectDebit)
                        {
                            DDExceptions = DDCCBatchFunctions.GetDDExceptions(fromDate, toDate, IsIntercompanySelected,
                                ((OperationsPrincipal)Thread.CurrentPrincipal).Identity.User.UserEntityId, selectedinternalCompanyBanks);
                        }
                        else if (receiptBatchType == ReceiptBatchType.CreditCard)
                        {
                            CCExceptions = DDCCBatchFunctions.GetCCExceptions(fromDate, toDate, IsIntercompanySelected, ((OperationsPrincipal)Thread.CurrentPrincipal).Identity.User.UserEntityId, selectedinternalCompanyBanks);
                        }
                    }

                    if (receiptBatchType == ReceiptBatchType.AutoReceipts)
                    {
                        newReceiptBatch = receiptBatch.Copy();

                        if (IsDateRangeApplicable)
                        {
                            newReceiptBatch.DateRangeFilterDescription = "From " + fromDate.ToString("dd/MM/yyyy") + " to " + toDate.ToString("dd/MM/yyyy");
                            newReceiptBatch.Receipts = new List<Receipt>();

                            foreach (OpenItemReceiptAllocation allocation in receiptAllocations.OrderBy(item => item.OpenItem.ContractID))
                            {
                                if (contractID != allocation.OpenItem.Contract.ContractId)
                                {
                                    receipt = new Receipt();
                                    receipt.ApplyToTypeID = (int)ReceiptApplyTo.Contract;
                                    receipt.ContractID = allocation.OpenItem.Contract.ContractId;
                                    receipt.InternalReference = receipt.ContractID.ToString();
                                    receipt.LastUserID = ((OperationsPrincipal)Thread.CurrentPrincipal).Identity.User.UserEntityId;
                                    receipt.LastDateModified = DateTime.Now;
                                    receipt.ReceiptDate = receiptBatch.ReceiptDate;

                                    receipt.GSTAmountReceived = 0;
                                    receipt.SDAmountReceived = 0;
                                    receipt.FIDAmountReceived = 0;
                                    receipt.NetAmountReceived = 0;
                                    receipt.GrossAmountReceived = 0;

                                    receipt.OpenItemReceiptAllocations = new List<OpenItemReceiptAllocation>();
                                    newReceiptBatch.Receipts.Add(receipt);
                                    newReceiptBatch.NumberOfEntries += 1;
                                    contractID = allocation.OpenItem.Contract.ContractId;
                                }

                                receipt.GSTAmountReceived += allocation.GSTAmountApplied.GetValueOrDefault();
                                receipt.SDAmountReceived += allocation.SDAmountApplied.GetValueOrDefault();
                                receipt.FIDAmountReceived += allocation.FIDAmountApplied.GetValueOrDefault();
                                receipt.NetAmountReceived += allocation.NetAmountApplied;
                                receipt.GrossAmountReceived += allocation.GrossAmountApplied.GetValueOrDefault();
                                newReceiptBatch.GrossBatchTotal += allocation.GrossAmountApplied.GetValueOrDefault();
                                allocation.OpenItem.Contract = null;
                                allocation.OpenItem = null;

                                receipt.OpenItemReceiptAllocations.Add(allocation);
                            }
                        }

                        ReceiptBatchFunctions.Save(newReceiptBatch, openItemIDs, fromDate, toDate);
                        ReturnValue = new NavigationItem() { ReceiptID = newReceiptBatch.ID, ReceiptText = newReceiptBatch.ID.ToString() + "-" + SelectedBatch, BatchStatus = (int)ReceiptBatchStatus.Created, BatchTypeID = newReceiptBatch.BatchTypeID };
                    }
                    else
                    {
                        foreach (InternalCompanyBank internalCompBank in selectedinternalCompanyBanks)
                        {
                            newReceiptBatch = receiptBatch.Copy();
                            newReceiptBatch.BankAccountID = internalCompBank.BankID;
                            newReceiptBatch.InternalCompanyNodeID = internalCompBank.NodeID;

                            if (isBankSelected)
                            {
                                newReceiptBatch.FilterDescription = "Bank: " + internalCompBank.BankName;
                            }
                            else if (IsIntercompanySelected)
                            {
                                newReceiptBatch.FilterDescription = "Internal Company: " + internalCompBank.InternalCompany;
                            }

                            if (IsDateRangeApplicable)
                            {
                                newReceiptBatch.DateRangeFilterDescription = "From " + fromDate.ToString("dd/MM/yyyy") + " to " + toDate.ToString("dd/MM/yyyy");
                                newReceiptBatch.Receipts = new List<Receipt>();

                                foreach (OpenItemReceiptAllocation allocation in receiptAllocations.Where(item => IsIntercompanySelected ? item.OpenItem.Contract.InternalCoyNodeId == internalCompBank.NodeID :
                                        item.OpenItem.Contract.LessorBankAccountId == internalCompBank.BankID))
                                {
                                    if (contractID != allocation.OpenItem.Contract.ContractId)
                                    {
                                        receipt = new Receipt();
                                        receipt.ApplyToTypeID = (int)ReceiptApplyTo.Contract;
                                        receipt.ContractID = allocation.OpenItem.Contract.ContractId;
                                        receipt.InternalReference = receipt.ContractID.ToString();
                                        receipt.LastUserID = ((OperationsPrincipal)Thread.CurrentPrincipal).Identity.User.UserEntityId;
                                        receipt.LastDateModified = DateTime.Now;
                                        receipt.ReceiptDate = receiptBatch.ReceiptDate;

                                        receipt.GSTAmountReceived = 0;
                                        receipt.SDAmountReceived = 0;
                                        receipt.FIDAmountReceived = 0;
                                        receipt.NetAmountReceived = 0;
                                        receipt.GrossAmountReceived = 0;

                                        if (receiptBatchType == ReceiptBatchType.DirectDebit)
                                        {
                                            receipt.DirectDebitReceiptDetails = new List<DirectDebitReceiptDetail>();
                                            receipt.DirectDebitReceiptDetails.Add(new DirectDebitReceiptDetail { LesseeBankAccountID = allocation.OpenItem.Contract.LesseeBankAccountId.GetValueOrDefault() });
                                        }
                                        else if (receiptBatchType == ReceiptBatchType.CreditCard)
                                        {
                                            receipt.CreditCardReceiptDetails = new List<CreditCardReceiptDetail>();
                                            receipt.CreditCardReceiptDetails.Add(new CreditCardReceiptDetail { LesseeBankAccountID = allocation.OpenItem.Contract.LesseeBankAccountId.GetValueOrDefault() });
                                        }

                                        receipt.OpenItemReceiptAllocations = new List<OpenItemReceiptAllocation>();
                                        newReceiptBatch.Receipts.Add(receipt);
                                        newReceiptBatch.NumberOfEntries += 1;
                                        contractID = allocation.OpenItem.Contract.ContractId;
                                    }

                                    receipt.GSTAmountReceived += allocation.GSTAmountApplied.GetValueOrDefault();
                                    receipt.SDAmountReceived += allocation.SDAmountApplied.GetValueOrDefault();
                                    receipt.FIDAmountReceived += allocation.FIDAmountApplied.GetValueOrDefault();
                                    receipt.NetAmountReceived += allocation.NetAmountApplied;
                                    receipt.GrossAmountReceived += allocation.GrossAmountApplied.GetValueOrDefault();
                                    newReceiptBatch.GrossBatchTotal += allocation.GrossAmountApplied.GetValueOrDefault();
                                    allocation.OpenItem.Contract = null;
                                    allocation.OpenItem = null;

                                    receipt.OpenItemReceiptAllocations.Add(allocation);
                                }

                                if (receiptBatchType == ReceiptBatchType.DirectDebit)
                                {
                                    newReceiptBatch.DirectDebitExceptions = DDExceptions.Where(item => (IsIntercompanySelected ? item.InternalCoyNodeId == internalCompBank.NodeID :
                                        (item.LessorBankAccountID == internalCompBank.BankID || item.LessorBankAccountID == null || item.LessorBankAccountID == -1))).
                                        Select(item => new model.DirectDebitException { AccountNumber = item.AccountNumber, AccountTitle = item.AccountTitle, BSBNumber = item.BSBNumber,
                                            CompanyName = item.CompanyName, ContractID = item.ContractID, CustomerName = item.CustomerName, DateCreated = item.DateCreated, Exception = item.Exception,
                                            GrossAmount = item.GrossAmount, ID = item.ID, LesseeBankAccountID = item.LesseeBankAccountID, LessorAccountNumber = item.LessorAccountNumber, LessorAccountTitle = item.LessorAccountTitle,
                                            LessorBankAccountID = item.LessorBankAccountID, LessorBSBNumber = item.LessorBSBNumber, PaymentDate = item.PaymentDate,  ReceiptBatchID = item.ReceiptBatchID, 
                                            UpdateRequired = item.UpdateRequired, UserID = item.UserID }).ToList();
                                }
                                else if (receiptBatchType == ReceiptBatchType.CreditCard)
                                {
                                    newReceiptBatch.CreditCardExceptions = CCExceptions.Where(item => (IsIntercompanySelected ? item.InternalCoyNodeId == internalCompBank.NodeID :
                                            (item.LessorBankAccountID == internalCompBank.BankID || item.LessorBankAccountID == null || item.LessorBankAccountID == -1))).Select(item => 
                                                new model.CreditCardException { AccountTitle = item.AccountTitle, CardNumber = item.CardNumber, CompanyName = item.CompanyName, CDTFMerchantNumber = item.CDTFMerchantNumber, 
                                                    ContractID = item.ContractID, CustomerName = item.CustomerName, DateCreated = item.DateCreated, Exception = item.Exception, ExpiryDate = item.ExpiryDate,
                                                    GrossAmount = item.GrossAmount, ID = item.ID, LesseeBankAccountID = item.LesseeBankAccountID, LessorAccountTitle = item.LessorAccountTitle, LessorBankAccountID = item.LessorBankAccountID,
                                                    MerchantNumber = item.MerchantNumber, PaymentDate = item.PaymentDate, ReceiptBatchID = item.ReceiptBatchID, UserID = item.UserID }).ToList();
                                }
                            }

                            ReceiptBatchFunctions.Save(newReceiptBatch, openItemIDs, fromDate, toDate);

                            ReturnValue = new NavigationItem() { ReceiptID = newReceiptBatch.ID, ReceiptText = newReceiptBatch.ID.ToString() + "-" + SelectedBatch, BatchStatus = (int)ReceiptBatchStatus.Created, BatchTypeID = newReceiptBatch.BatchTypeID };
                        }
                    }

                    Close();
                }
                else if (receiptBatchType == ReceiptBatchType.Dishonour || receiptBatchType == ReceiptBatchType.Reversals)
                {
                    if (selectedReceipts != null)
                    {
                        var banksList = selectedReceipts.Select(item => ((DishonourReversalReceiptSearch)item).BankAccountID).Distinct().ToList();

                        foreach (int bankID in banksList)
                        {
                            newReceiptBatch = receiptBatch.Copy();
                            newReceiptBatch.BankAccountID = bankID;
                            newReceiptBatch.FilterDescription = "Bank: " + ((DishonourReversalReceiptSearch)selectedReceipts.Where(item => ((DishonourReversalReceiptSearch)item).BankAccountID == bankID).FirstOrDefault()).BankName;
                            newReceiptBatch.Receipts.Clear();

                            foreach (DishonourReversalReceiptSearch selectedReceipt in selectedReceipts.Where(item => ((DishonourReversalReceiptSearch)item).BankAccountID == bankID))
                            {
                                receipt = new Receipt();

                                if (selectedReceipt.ContractNo != null)
                                {
                                    receipt.ApplyToTypeID = (int)ReceiptApplyTo.Contract;
                                    receipt.InternalReference = selectedReceipt.ContractNo.ToString();
                                }
                                else
                                {
                                    receipt.ApplyToTypeID = (int)ReceiptApplyTo.Quote;
                                    receipt.InternalReference = selectedReceipt.QuoteID.ToString();
                                }
                                receipt.ContractID = selectedReceipt.ContractNo;
                                receipt.QuoteID = selectedReceipt.QuoteID;

                                if (receiptBatchType == ReceiptBatchType.Dishonour)
                                {
                                    receipt.Reference = "Dishonour";
                                }
                                else
                                {
                                    receipt.Reference = "Reversal";
                                }

                                receipt.LastUserID = ((OperationsPrincipal)Thread.CurrentPrincipal).Identity.User.UserEntityId;
                                receipt.LastDateModified = DateTime.Now;
                                receipt.ReceiptDate = receiptBatch.ReceiptDate;

                                receipt.NetAmountReceived = selectedReceipt.NetAmountReceived.GetValueOrDefault() * -1;
                                receipt.GSTAmountReceived = selectedReceipt.GSTAmountReceived.GetValueOrDefault() * -1;
                                receipt.FIDAmountReceived = selectedReceipt.FIDAmountReceived.GetValueOrDefault() * -1;
                                receipt.SDAmountReceived = selectedReceipt.SDAmountReceived.GetValueOrDefault() * -1;
                                receipt.GrossAmountReceived = selectedReceipt.AmountReceived * -1;

                                if (receiptBatchType == ReceiptBatchType.Dishonour)
                                {
                                    receipt.DishonourReceiptDetail = new DishonourReceiptDetail { DishonouredReceiptID = selectedReceipt.ReceiptID };
                                }
                                else
                                {
                                    receipt.ReversalReceiptDetail = new ReversalReceiptDetail { LinkedReceiptID = selectedReceipt.ReceiptID, ReversalTypeID = (int)ReversalTypes.Reversal };
                                }

                                foreach (OpenItemReceiptAllocation allocation in DishonourReversalFunctions.GetOpenItemReceiptAllocations(selectedReceipt.ReceiptID))
                                {
                                    newAllocation = new OpenItemReceiptAllocation();

                                    newAllocation.OpenItemID = allocation.OpenItemID;
                                    newAllocation.NetAmountApplied = allocation.NetAmountApplied * -1;
                                    newAllocation.GSTAmountApplied = allocation.GSTAmountApplied * -1;
                                    newAllocation.FIDAmountApplied = allocation.FIDAmountApplied * -1;
                                    newAllocation.SDAmountApplied = allocation.SDAmountApplied * -1;
                                    newAllocation.GrossAmountApplied = allocation.GrossAmountApplied * -1;
                                    receipt.OpenItemReceiptAllocations.Add(newAllocation);
                                }

                                newReceiptBatch.Receipts.Add(receipt);
                                newReceiptBatch.GrossBatchTotal += receipt.GrossAmountReceived;
                                newReceiptBatch.NumberOfEntries++;
                            }

                            ReceiptBatchFunctions.Save(newReceiptBatch);
                            ReturnValue = new NavigationItem() { ReceiptID = newReceiptBatch.ID, ReceiptText = newReceiptBatch.ID.ToString() + "-" + SelectedBatch, BatchStatus = (int)ReceiptBatchStatus.Created, BatchTypeID = newReceiptBatch.BatchTypeID };
                        }

                        Close();
                    }
                    else
                    {
                        ReceiptBatchFunctions.Save(receiptBatch);

                        if (isNew && createFromList.Where(from => from.ID == createFrom).FirstOrDefault().Description.ToLower().Trim() == ReceiptBatchCreateFrom.Import.ToString().ToLower().Trim())
                        {
                            ReturnValue = new NavigationItem() { ReceiptID = receiptBatch.ID, ReceiptText = receiptBatch.ID.ToString() + "-" + SelectedBatch, BatchStatus = (int)ReceiptBatchStatus.Created, BatchTypeID = receiptBatch.BatchTypeID };

                            IsBusy = true;
                            popupWindow = new PopupWindow(ViewAssemblies.ReceiptsViewAssembly, "DishonourReversal.DishonourReversalReceiptExcelImport", true);
                            popupWindow.Parameters.Add(receiptBatchType);
                            popupWindow.Parameters.Add(receiptBatch.ID);
                            Popup.Raise(popupWindow);
                            receiptBatch = ReceiptBatchFunctions.Get(receiptBatch.ID);
                            IsBusy = false;
                        }
                        else
                        {
                            ReturnValue = new NavigationItem() { ReceiptID = receiptBatch.ID, ReceiptText = receiptBatch.ID.ToString() + "-" + SelectedBatch, BatchStatus = (int)ReceiptBatchStatus.Created, BatchTypeID = receiptBatch.BatchTypeID };
                            Close();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionLogger.WriteLog(ex);
                ShowErrorMessage("Error encountered while Creating New Batch.", "Create Batch - Error");
            }
            finally
            {
                IsBusy = false;                     
            }
        }
 public AddReceiptsViewModel()
 {
     ReceiptBatch = new ReceiptBatch();
     ReceiptBatch.ReceiptDate = DateTime.Today;
     Popup = new InteractionRequest<PopupWindow>();
 }