public SupplierInvoiceSettlementViewModel GetSupplierByMainCodeSubCode(string mainCode, string subCode)
        {
            var result   = new SupplierInvoiceSettlementViewModel();
            var supplier = _supplierRepository.Query(i => i.SupplierMainC == mainCode && i.SupplierSubC == subCode).FirstOrDefault();

            if (supplier != null)
            {
                var viewModel = Mapper.Map <Supplier_M, SupplierViewModel>(supplier);
                var index     = FindIndex(supplier.SupplierMainC, supplier.SupplierSubC);
                viewModel.SupplierIndex = index;
                result.Supplier         = viewModel;

                if (!string.IsNullOrEmpty(viewModel.InvoiceMainC) && !string.IsNullOrEmpty(viewModel.InvoiceSubC))
                {
                    var invoice          = _supplierRepository.Query(cus => cus.SupplierMainC == viewModel.InvoiceMainC && cus.SupplierSubC == viewModel.InvoiceSubC).FirstOrDefault();
                    var invoiceViewModel = Mapper.Map <Supplier_M, SupplierInvoiceViewModel>(invoice);
                    result.Invoice = invoiceViewModel;

                    // get settlement list
                    var settlementList = _supplierSettlementRepository.Query(set => set.SupplierMainC == viewModel.InvoiceMainC && set.SupplierSubC == viewModel.InvoiceSubC).OrderBy(i => i.ApplyD).ToList();
                    result.SettlementList = Mapper.Map <List <SupplierSettlement_M>, List <SupplierSettlementViewModel> >(settlementList);
                }

                result.Status = Convert.ToInt32(SupplierStatus.Edit);
            }
            else
            {
                supplier = _supplierRepository.Query(i => i.SupplierMainC == mainCode && i.SupplierSubC == "000").FirstOrDefault();
                if (supplier != null)
                {
                    var viewModel = Mapper.Map <Supplier_M, SupplierViewModel>(supplier);
                    result.Supplier = viewModel;
                    result.Supplier.SupplierSubC = subCode;

                    if (!string.IsNullOrEmpty(viewModel.InvoiceMainC) && !string.IsNullOrEmpty(viewModel.InvoiceSubC))
                    {
                        var invoice          = _supplierRepository.Query(cus => cus.SupplierMainC == viewModel.InvoiceMainC && cus.SupplierSubC == viewModel.InvoiceSubC).FirstOrDefault();
                        var invoiceViewModel = Mapper.Map <Supplier_M, SupplierInvoiceViewModel>(invoice);
                        result.Invoice = invoiceViewModel;

                        // get settlement list
                        var settlementList = _supplierSettlementRepository.Query(set => set.SupplierMainC == viewModel.InvoiceMainC && set.SupplierSubC == viewModel.InvoiceSubC).OrderBy(i => i.ApplyD).ToList();
                        result.SettlementList = Mapper.Map <List <SupplierSettlement_M>, List <SupplierSettlementViewModel> >(settlementList);
                    }
                    result.Status = Convert.ToInt32(SupplierStatus.Add);
                }
                else
                {
                    result.Status = Convert.ToInt32(SupplierStatus.Add);
                }
            }
            return(result);
        }
        public SupplierInvoiceSettlementViewModel GetSupplierSettlementList(string supplierMainC, string supplierSubC)
        {
            SupplierInvoiceSettlementViewModel result = new SupplierInvoiceSettlementViewModel();

            // get invoice info
            var invoice          = _supplierRepository.Query(cus => cus.SupplierMainC == supplierMainC && cus.SupplierSubC == supplierSubC).FirstOrDefault();
            var invoiceViewModel = Mapper.Map <Supplier_M, SupplierInvoiceViewModel>(invoice);

            result.Invoice = invoiceViewModel;

            var settlementList          = _supplierSettlementRepository.Query(set => set.SupplierMainC == supplierMainC && set.SupplierSubC == supplierSubC).OrderBy(i => i.ApplyD).ToList();
            var settlementListViewModel = Mapper.Map <List <SupplierSettlement_M>, List <SupplierSettlementViewModel> >(settlementList);

            result.SettlementList = settlementListViewModel;

            return(result);
        }