public ActionResult Create()
        {
            AddInvoiceViewModel viewModel = new AddInvoiceViewModel();

            // viewModel.CreatedOn = DateTime.Now;
            return(View(viewModel));
        }
Exemplo n.º 2
0
        public AddInvoiceView(EventModel eventModel)
        {
            InitializeComponent();
            DataContext = _viewModel = new AddInvoiceViewModel(eventModel);

            Owner = Application.Current.MainWindow;
        }
Exemplo n.º 3
0
        private bool ValidateInvoiceData(AddInvoiceViewModel vm)
        {
            bool result = false;

            if (!String.IsNullOrEmpty(vm.IMAGEID))
            {
                // Verify image file path.
                string imagePath = GSA.R7BD.Utility.Utilities.GetImageNowPath(vm.IMAGEID);
                if (!string.IsNullOrEmpty(imagePath) && System.IO.File.Exists(imagePath))
                {
                    vm.IMAGEPATH = imagePath;

                    // Grab page count.
                    string extension = Path.GetExtension(imagePath);
                    byte   pageCount = 1;
                    if (extension == ".tiff" || extension == ".tif")
                    {
                        TIF TheFile = new TIF(imagePath);
                        pageCount = (byte)TheFile.PageCount;
                        TheFile.Dispose();
                    }

                    vm.DOCPAGE = pageCount;
                    result     = true;
                }
            }
            return(result);
        }
Exemplo n.º 4
0
        public async Task <IActionResult> AddInvoice([FromBody] AddInvoiceViewModel addInvoiceViewModel)
        {
            var command = new AddInvoiceCommand(InvoiceId.New, addInvoiceViewModel.Title);
            await _commandBus.PublishAsync(command, CancellationToken.None);

            return(Ok());
        }
Exemplo n.º 5
0
        public ActionResult RejectInvoice(AddInvoiceViewModel viewModel)
        {
            string errorMessage = "";

            prepcode = this.PrepCode;

            // Format reason string.
            string reason = DateTime.Now.ToString() + " " + prepcode;

            reason += " - " + viewModel.REJECTOPTION + " / " + viewModel.REJECTDESCRIPTION;

            // Mark invoice as rejected.
            if (!RejectPegasysInvoice(viewModel))
            {
                errorMessage = "Reject invoice failed. ";
            }

            // Write transhist entry.
            string    memo  = "Image Rejected from data entry - " + reason;
            var       mgrTH = new TransHistManager();
            TRANSHIST th    = CreateTransHistForChange(viewModel, memo, DataEntry.ImgReject);

            mgrTH.InsertTransHist(th);

            // Update imagelist.
            var       mgrIL = new ImageListManager();
            IMAGELIST il    = mgrIL.GetImageListByImageId(viewModel.IMAGEID);

            if (il != null)
            {
                // Mark as rejected and update.
                mgrIL.RejectImageList(viewModel.IMAGEID, prepcode, reason);
            }
            else
            {
                var           mgrILH = new ImageListHistManager();
                IMAGELISTHIST ilh    = mgrILH.GetImageListHistByImageId(viewModel.IMAGEID);
                if (ilh != null)
                {
                    // Convert to ImageList and mark as rejected.
                    il = mgrIL.MapToImageList(ilh);
                    MarkImageListAsRejected(il, reason);
                    // Add to ImageList.
                    mgrIL.InsertImageList(il);
                    // Remove from ImageListHist.
                    mgrILH.DeleteImageListHist(ilh);
                }
                else
                {
                    // Uh oh. No imagelisthist entry.
                    errorMessage += viewModel.IMAGEID + " does not exist in the ImageListHist table.";
                }
            }

            // Reload the index page to move to the next invoice, if available.
            TempData["ErrorMessage"] = errorMessage;
            return(RedirectToAction("Index", new { InvoiceType = viewModel.INVOICETYPE }));
        }
Exemplo n.º 6
0
        public ActionResult AddInvoice(AddInvoiceViewModel viewModel)
        {
            prepcode = this.PrepCode;

            // Key this invoice.
            if (!KeyPegasysInvoice(viewModel))
            {
                TempData["ErrorMessage"] = "Update failed for invoice " + viewModel.INV_KEY_ID;
            }

            // Write transhist entries.
            string memo       = "";
            string allProcess = "";

            switch (viewModel.INVOICETYPE)
            {
            case DataEntry.TypeTops:
                memo       = DataEntry.TopsMemo;
                allProcess = DataEntry.TopsAllProcess;
                break;

            case DataEntry.TypeNonTops:
                memo       = (viewModel.GENE043S ? DataEntry.NonTopsMemoError : DataEntry.NonTopsMemo);
                allProcess = DataEntry.NonTopsAllProcess;
                break;

            case DataEntry.TypeConst:
                memo       = (viewModel.GENE043S ? DataEntry.ConstMemoError : DataEntry.ConstMemo);
                allProcess = DataEntry.ConstAllProcess;
                break;

            case DataEntry.TypeNonConst:
                memo       = DataEntry.NonConstMemo;
                allProcess = DataEntry.NonConstAllProcess;
                break;

            default:
                // Shouldn't get here.
                break;
            }
            var       mgrTH = new TransHistManager();
            TRANSHIST th    = CreateTransHistForChange(viewModel, memo, allProcess);

            mgrTH.InsertTransHist(th);
            var            mgrITH = new ImageTransHistManager();
            IMAGETRANSHIST ith    = CreateImageTransHistForChange(viewModel, memo);

            mgrITH.InsertImageTransHist(ith);

            // Reload the index page to move to the next invoice, if available.
            return(RedirectToAction("Index", new { InvoiceType = viewModel.INVOICETYPE }));
        }
        public IActionResult AddInvoice(AddInvoiceViewModel model)
        {
            var customer = _repo.GetCustomerById(model.CustomerId);

            var newInvoice = new Invoice()
            {
                Customer      = customer,
                InvoiceNumber = model.InvoiceNumber,
                Date          = DateTime.Now
            };

            _repo.AddInvoice(newInvoice);

            return(RedirectToAction("InvoiceDetails", new { invoiceId = newInvoice.InvoiceID }));
        }
Exemplo n.º 8
0
 public StoreViewModel(Window user, Window invoice, Window inventory, Window product)
 {
     addUserViewModel      = new AddPersonViewModel();
     addInventoryViewModel = new AddInventoryViewModel();
     addInvoiceViewModel   = new AddInvoiceViewModel();
     addProductViewModel   = new AddProductViewModel();
     AddPersonCommand      = new AddPersonButtonCommand(this);
     AddInventoryCommand   = new AddInventoryButtonCommand(this);
     AddInvoiceCommand     = new AddInvoiceButtonCommand(this);
     AddProductCommand     = new AddProductButtonCommand(this);
     this.user             = user;
     this.invoice          = invoice;
     this.inventory        = inventory;
     this.product          = product;
 }
 public ViewModelLocator()
 {
     if (!DesignerProperties.GetIsInDesignMode(new DependencyObject()))
     {
         MainViewModel             = new MainViewModel();
         HomeViewModel             = new HomeViewModel();
         PaymentsViewModel         = new PaymentsViewModel();
         InvoiceViewModel          = new InvoicesViewModel();
         AddPaymentViewModel       = new AddPaymentViewModel();
         AddInvoiceViewModel       = new AddInvoiceViewModel();
         InvoiceDetailsViewModel   = new InvoiceDetailsViewModel();
         PaymentDetailsViewModel   = new PaymentDetailsViewModel();
         BalanceStatementViewModel = new BalanceStatementViewModel();
     }
 }
Exemplo n.º 10
0
        public ActionResult Add()
        {
            var user = this.userService.GetById(this.User.Identity.GetUserId());

            if (user.Site == null)
            {
                return(Redirect("/Invoices/Invoice/MemberOfSite"));
            }

            //Generate default invoice number
            var number = (this.invoiceService.GetAll().Count + 1001).ToString();

            while (this.invoiceService.Exist(number, user.Site.OrganisationId))
            {
                number = (int.Parse(number) + 1).ToString();
            }

            //Set viewmodel data
            var viewModel = new AddInvoiceViewModel
            {
                InvoiceNumber = number,
                Currencies    = this.currencyService.GetAll().ToList()
                                .Where(x => x.OrganisationId == user.Site.OrganisationId)
                                .ToList()
                                .ConvertAll(x => new CurrencyViewModel
                {
                    Code = x.Code,
                    Id   = x.Id
                }),
                BillToAddress      = user.Site.Organisation.Address,
                BillToOrganisation = user.Site.Organisation.Name,
                BillToSite         = user.Site.Name
            };

            //Set default invoiee currency by user organisation
            if (user.Site != null)
            {
                if (user.Site.Organisation.Bill != null)
                {
                    var billCurrencyId = user.Site.Organisation.Bill.CurrencyId;
                    var billRealItem   = viewModel.Currencies.Where(x => x.Id == billCurrencyId).FirstOrDefault();

                    viewModel.Currencies.Remove(billRealItem);
                    viewModel.Currencies.Insert(0, billRealItem);
                }
            }
            return(View(viewModel));
        }
Exemplo n.º 11
0
        private TRANSHIST CreateTransHistForChange(AddInvoiceViewModel inv, string memo, string allProcess)
        {
            var th = new TRANSHIST()
            {
                TH_ID      = null,
                PDOCNO     = inv.PDOCNOPO,
                TRANSDATE  = DateTime.Now,
                INV_KEY_ID = inv.INV_KEY_ID,
                ACT        = inv.ACT,
                ALLPROCESS = allProcess,
                TRANSAMT   = inv.AMOUNT,
                PREPCODE   = prepcode,
                CUFF_MEMO  = memo
            };

            return(th);
        }
Exemplo n.º 12
0
        private bool RejectPegasysInvoice(AddInvoiceViewModel viewModel)
        {
            // Grab the full invoice.
            PEGASYSINVOICE invoice = pegInvoiceManager.GetPegasysInvoiceByKeyId(viewModel.INV_KEY_ID);

            if (invoice == null)
            {
                return(false);
            }

            // Set rejection fields.
            invoice.OUT        = null;
            invoice.OUTPREP    = null;
            invoice.OUTDATE    = null;
            invoice.INV_STATUS = DataEntry.ImgReject;

            // Update it.
            return(pegInvoiceManager.UpdatePegasysInvoiceReturnResult(invoice));
        }
Exemplo n.º 13
0
        private void FormatInvoiceData(PEGASYSINVOICE invoice, AddInvoiceViewModel vm)
        {
            // Grab the legal business name from Pegasys, if it exists.
            string legalBusinessName = pegInvoiceManager.GetLegalBusinessName(invoice);

            // Address text area is as follows:
            // legalBusinessName
            // ADDR_L1
            // ADDR_L2
            // ADDR_L3
            // ADDR_CITY, ADDR_STATE ADDR_ZPCD
            string address = "";

            if (!string.IsNullOrEmpty(legalBusinessName))
            {
                address = legalBusinessName + "\n";
            }
            if (!string.IsNullOrEmpty(invoice.ADDR_L1))
            {
                address += invoice.ADDR_L1 + "\n";
            }
            if (!string.IsNullOrEmpty(invoice.ADDR_L2))
            {
                address += invoice.ADDR_L2 + "\n";
            }
            if (!string.IsNullOrEmpty(invoice.ADDR_L3))
            {
                address += invoice.ADDR_L3 + "\n";
            }
            if (!string.IsNullOrEmpty(invoice.ADDR_CITY))
            {
                address += invoice.ADDR_CITY;
            }
            if (!string.IsNullOrEmpty(invoice.ADDR_STATE))
            {
                address += ", " + invoice.ADDR_STATE;
            }
            if (!string.IsNullOrEmpty(invoice.ADDR_ZPCD))
            {
                address += " " + invoice.ADDR_ZPCD;
            }
            vm.VENDADDRESS = address;
        }
Exemplo n.º 14
0
        private bool KeyPegasysInvoice(AddInvoiceViewModel viewModel)
        {
            // Grab the full invoice.
            PEGASYSINVOICE invoice = pegInvoiceManager.GetPegasysInvoiceByKeyId(viewModel.INV_KEY_ID);

            if (invoice == null)
            {
                return(false);
            }

            // Update invoice with our view model.
            invoice = AddInvoiceViewModel.MapToEntityFramework(viewModel, invoice);

            // Set keying specific fields.
            invoice.OUT          = "F";
            invoice.OUTPREP      = null;
            invoice.OUTDATE      = null;
            invoice.DATAENTRY_FL = "T";
            invoice.KEYDATE      = DateTime.Now;
            invoice.KEYPC        = prepcode;
            invoice.PREPCODE     = prepcode;
            invoice.INV_STATUS   = DataEntry.Keyed;

            if (!viewModel.VENDORMATCH)
            {
                invoice.ADDR_L1      = null;
                invoice.ADDR_L2      = null;
                invoice.ADDR_L3      = null;
                invoice.ADDR_CITY    = null;
                invoice.ADDR_STATE   = null;
                invoice.ADDR_ZPCD    = null;
                invoice.VEND_ADDR_CD = DataEntry.VendAddrCd;
            }

            if (viewModel.GENE043S)
            {
                invoice.NEEDERR_CODE = DataEntry.NeedErrCode;
            }

            // Update it.
            return(pegInvoiceManager.UpdatePegasysInvoiceReturnResult(invoice));
        }
Exemplo n.º 15
0
        public StoreViewModel(Window user, Window invoice, Window inventory, Window product)
        {
            this.store = new Store();

            addUserViewModel      = new AddPersonViewModel(this.store);
            addInventoryViewModel = new AddInventoryViewModel(this.store);
            addInvoiceViewModel   = new AddInvoiceViewModel(this.store);
            addProductViewModel   = new AddProductViewModel(this.store);
            viewAllViewModel      = new ViewAllViewModel(this.store);
            viewAllProductsModel  = new ViewAllProductsModel(this.store);
            viewAllEventsModel    = new ViewAllEventsModel(this.store);


            AddViewAllCommand      = new AddViewAllCommand(this);
            ViewAllProductsCommand = new ViewAllProductsCommand(this);
            ViewAllEventsCommand   = new ViewAllEventsCommand(this);
            AddPersonCommand       = new AddPersonButtonCommand(this);
            AddInventoryCommand    = new AddInventoryButtonCommand(this);
            AddInvoiceCommand      = new AddInvoiceButtonCommand(this);
            AddProductCommand      = new AddProductButtonCommand(this);
        }
        public void Create(AddInvoiceViewModel viewModel)
        {
            var invoice = new Invoice
            {
                Number     = viewModel.Number,
                CustomerId = viewModel.CustomerId,
                CreatedOn  = PersianDateTime.Parse(viewModel.CreatedOnString).ToDateTime(),
                Items      = new List <InvoiceItem>()
            };

            foreach (var item in viewModel.Items)
            {
                var invoiceItem = new InvoiceItem
                {
                    ProductId = item.ProductId,
                    Price     = item.Price,
                    Quantity  = item.Quantity
                };
                invoice.Items.Add(invoiceItem);
            }
            ServiceFactory.Create <IInvoiceService>().SaveInvoice(invoice);
        }
Exemplo n.º 17
0
        private IMAGETRANSHIST CreateImageTransHistForChange(AddInvoiceViewModel inv, string memo)
        {
            var th = new IMAGETRANSHIST()
            {
                IMG_TH_ID    = null,
                IMG_KEY_ID   = "NONE",
                IMAGEBATCH   = inv.IMAGEBATCH,
                BATCH_INDEX  = "NO",
                STATUS       = "K",
                QUEUE        = "",
                VITAP_KEY_ID = inv.INV_KEY_ID,
                IMAGETYPE    = "INV",
                PROCESS      = DataEntry.Keyed,
                SOURCE       = DataEntry.Keyed,
                PDOCNO       = inv.PDOCNOPO,
                ACT          = inv.ACT,
                PREPCODE     = prepcode,
                IMAGEID      = inv.IMAGEID,
                NOTES        = memo
            };

            return(th);
        }
Exemplo n.º 18
0
 public AddInvoiceCommand(AddInvoiceViewModel viewModel)
 {
     this.viewModel = viewModel;
 }
Exemplo n.º 19
0
        public ActionResult Add(AddInvoiceViewModel model)
        {
            var userOrg = this.userService.GetById(this.User.Identity.GetUserId()).Site.OrganisationId;

            //Check if exist a invoice with same invoice number
            if (this.invoiceService.Exist(model.InvoiceNumber, userOrg))
            {
                model.Currencies = this.currencyService.GetAll()
                                   .Where(x => x.OrganisationId == userOrg)
                                   .ToList()
                                   .ConvertAll(x => new CurrencyViewModel
                {
                    Code = x.Code,
                    Id   = x.Id
                });

                this.ModelState.AddModelError("", InvoiceTr.SameNum);
                return(View(model));
            }

            //Check the is the provider selected and are there selected items
            if (((model.ItemIds == null || model.ItemIds.Count == 0) && (model.ProviderId == 0)) || (!ModelState.IsValid))
            {
                model.Currencies = this.currencyService.GetAll()
                                   .Where(x => x.OrganisationId == userOrg)
                                   .ToList()
                                   .ConvertAll(x => new CurrencyViewModel
                {
                    Code = x.Code,
                    Id   = x.Id
                });

                if (model.ProviderId == 0)
                {
                    ModelState.AddModelError("ProviderId", InvoiceTr.ProviderIsRequired);
                }

                if (model.ItemIds == null || model.ItemIds.Count == 0)
                {
                    ModelState.AddModelError("ItemIds", InvoiceTr.MustSelectItems);
                }
                return(View(model));
            }

            //-------------------------------------------------------------------------------
            //Convert item to real id and calculate the price of invoice

            double price = 0;
            int    flag  = 0;

            if (model.ItemIds != null)
            {
                for (int i = 0; i < model.ItemIds.Count; i++)
                {
                    if (model.ItemIds[i].Last() == 'f')
                    {
                        model.ItemIds[i] = model.ItemIds[i].Remove(model.ItemIds[i].Count() - 1, 1);
                    }
                }


                foreach (var item in model.ItemIds)
                {
                    var realItem = this.itemService.GetById(int.Parse(item));

                    var currencyCourse = this.exchangeService.GetRate(realItem.Price.CurrencyId, model.SelectedCurrency);

                    price += realItem.Price.Value * currencyCourse * model.Items[flag];

                    flag++;
                }
            }

            if (model.PoId != null && model.PoId.HasValue)
            {
                var PO = this.requestToProviderService.GetById(model.PoId.Value);

                foreach (var item in PO.GiveItems)
                {
                    var currencyCourse = this.exchangeService.GetRate(item.Price.CurrencyId, model.SelectedCurrency);

                    price += item.Price.Value * currencyCourse * PO.CountItems.Where(x => x.Key == item.Id).FirstOrDefault().Give;
                }
            }

            //-------------------------------------------------------------------------------
            // Add a invoice to database

            var id = this.invoiceService.Add(new Invoice
            {
                CompiledUserId      = this.User.Identity.GetUserId(),
                DateOfCreation      = DateTime.Now,
                Number              = model.InvoiceNumber,
                ProviderId          = model.ProviderId,
                RecipientMOL        = model.RecipientMOL,
                RequestToProviderId = model.PoId,
                Price = new Price
                {
                    CurrencyId = model.SelectedCurrency,
                    Value      = price
                },
                PaymentPeriod = model.DateOfPayment
            });

            //Add items to invoice
            if (model.ItemIds != null)
            {
                this.invoiceService.AddItems(id, model.ItemIds.ConvertAll(x => int.Parse(x)), model.Items);
            }

            //-------------------------------------------------------------------------------
            //Add event that there is a new invoice

            this.eventService.AddForUserGroup(new Event
            {
                Content            = "You have a new invoice for approving !",
                Date               = DateTime.Now,
                EventRelocationUrl = "/Invoices/Invoice/InvoicesForApproving"
            },
                                              "Approve invoice",
                                              this.userService.GetUserOrganisationId(this.User.Identity.GetUserId()));

            return(Redirect("/Home/Index"));
        }
Exemplo n.º 20
0
        public ActionResult Index(string InvoiceType)
        {
            string batchPrefix     = null;
            AddInvoiceViewModel vm = new AddInvoiceViewModel();

            ViewBag.Message      = "";
            ViewBag.ErrorMessage = TempData["ErrorMessage"];
            prepcode             = this.PrepCode;

            switch (InvoiceType)
            {
            case DataEntry.TypeTops:
                // TOPS
                batchPrefix = pegInvoiceManager.GetBatchPrefixByConfigValue(DataEntry.BatchPrefixTopsConfig);
                if (String.IsNullOrEmpty(batchPrefix))
                {
                    batchPrefix = DataEntry.BatchPrefixTopsDefault;
                }
                break;

            case DataEntry.TypeNonTops:
                // Non Tops
                batchPrefix = pegInvoiceManager.GetBatchPrefixByConfigValue(DataEntry.BatchPrefixNonTopsConfig);
                if (String.IsNullOrEmpty(batchPrefix))
                {
                    batchPrefix = DataEntry.BatchPrefixNonTopsDefault;
                }
                break;

            case DataEntry.TypeConst:
                // Construction
                batchPrefix = pegInvoiceManager.GetBatchPrefixByConfigValue(DataEntry.BatchPrefixConstConfig);
                if (String.IsNullOrEmpty(batchPrefix))
                {
                    batchPrefix = DataEntry.BatchPrefixConstDefault;
                }
                break;

            case DataEntry.TypeNonConst:
                // Non Construction
                batchPrefix = pegInvoiceManager.GetBatchPrefixByConfigValue(DataEntry.BatchPrefixNonConstConfig);
                if (String.IsNullOrEmpty(batchPrefix))
                {
                    batchPrefix = DataEntry.BatchPrefixNonConstDefault;
                }
                break;

            default:
                // Not supported. Will return null view.
                return(View(vm));
            }

            pegInvoiceManager.UpdateFailedDataEntries();
            var invoices = GetKeyablePegasysInvoicesByBatchPrefix(batchPrefix);

            // Find the first invoice that hasn't been keyed.
            if (invoices.Count > 0)
            {
                foreach (var invoice in invoices)
                {
                    AddInvoiceViewModel thisVM = AddInvoiceViewModel.MapToViewModel(invoice);
                    // Validate and claim this invoice.
                    if (ValidateInvoiceData(thisVM) &&
                        ClaimPegasysInvoiceForKeying(invoice))
                    {
                        // Go with this one.
                        FormatInvoiceData(invoice, thisVM);
                        vm = thisVM;
                        break;
                    }
                }
            }

            // Find any with working images?
            if (vm.IMAGEID == null)
            {
                if (!String.IsNullOrEmpty(ViewBag.ErrorMessage))
                {
                    ViewBag.ErrorMessage += "<br />";
                }
                ViewBag.ErrorMessage += DataEntry.NoValidInvoicesFound;
            }

            ViewBag.InvoiceType = InvoiceType ?? default(string);
            vm.INVOICETYPE      = InvoiceType ?? default(string);
            return(View(vm));
        }