コード例 #1
0
 public IActionResult Add(InvoiceViewModel invoiceViewModel)
 {
     if (invoiceViewModel.Id == 0)
     {
         ModelState.Remove("Id");
         if (ModelState.IsValid)
         {
             var invoice = _mapper.Map <Invoice>(invoiceViewModel);
             _invoice.AddInvoice(invoice);
             _toastNotification.AddSuccessToastMessage("تم أضافة بيانات الفاتورة بنجاح");
             return(RedirectToAction(nameof(Index)));
         }
         return(View(invoiceViewModel));
     }
     else
     {
         if (ModelState.IsValid)
         {
             var invoicedata = _mapper.Map <Invoice>(invoiceViewModel);
             invoicedata.Note = invoiceViewModel.Note;
             _invoice.UpdateInvoice(invoiceViewModel.Id, invoicedata);
             _toastNotification.AddSuccessToastMessage("تم تعديل بيانات الفاتورة بنجاح");
             return(RedirectToAction(nameof(Index)));
         }
         return(View(invoiceViewModel));
     }
 }
コード例 #2
0
        public IActionResult AddInvoice([FromBody] DTOs.Invoice invoiceForCreate)
        {
            Entities.Invoice invoice;
            List <Entities.InvoiceDetail> invoiceDetails;

            try
            {
                invoice        = _mapper.Map <Entities.Invoice>(invoiceForCreate);
                invoice.UserId = "preicher";


                var invoiceToAdd = _invoiceRepository.AddInvoice(invoice);
                invoiceDetails = invoiceForCreate.InvoiceDetails.Select(d => new Entities.InvoiceDetail(invoiceToAdd.InvoiceId, "preicher", d)).ToList();
                invoiceDetails.ForEach(invDtl => _invoiceRepository.AddInvoiceDetail(invDtl));
            }
            catch (Exception ex)
            {
                Log.Error(ex.Message);
                return(StatusCode(500));
            }
            var InvoiceToSend = _mapper.Map <DTOs.Invoice>(invoice);

            foreach (var itm in invoiceDetails)
            {
                InvoiceToSend.InvoiceDetails.Add(new DTOs.InvoiceDetail(itm.budgetCategoryId, itm.budgetId, itm.InvAmt));
            }

            InvoiceToSend.DocCnt = 0;
            return(Ok(InvoiceToSend));
        }
コード例 #3
0
        public async Task <ActionResult <InvoiceServiceResponse> > CreateInvoice(Invoice invoice)
        {
            var response = new InvoiceServiceResponse();

            try
            {
                if (invoice == null)
                {
                    response.ResponseCode    = StatusCodes.Status422UnprocessableEntity;
                    response.ResponseMessage = "Invalid data supplied";
                    return(response);
                }

                var inv = await _invoiceRepository.GetInvoiceByOrderNuber(invoice.OrderNumber);

                if (inv != null)
                {
                    response.ResponseCode    = StatusCodes.Status409Conflict;
                    response.ResponseMessage = "Duplicate data is not allowed,Order number already in use.";
                    return(response);
                }

                var createdInvoice = await _invoiceRepository.AddInvoice(invoice);

                response.ResponseCode    = StatusCodes.Status201Created;
                response.ResponseMessage = createdInvoice.Description + " was created successfully";
                return(response);
            }
            catch (Exception exp)
            {
                response.ResponseCode    = StatusCodes.Status500InternalServerError;
                response.ResponseMessage = "Internal server error occurred " + exp.StackTrace;
                return(response);
            }
        }
コード例 #4
0
 public async Task <IActionResult> PostInvoice(Invoice invoice)
 {
     if (await _repository.AddInvoice(invoice))
     {
         return(CreatedAtAction("GetInvoice", new { id = invoice.InvoiceID }, invoice));
     }
     else
     {
         return(StatusCode(500));
     }
 }
コード例 #5
0
        public async Task <ActionResult <Invoice> > CreateInvoice([FromBody] Invoice invoice)
        {
            try
            {
                var invoiceToCreate = await _invoiceRepsoitory.AddInvoice(invoice);

                return(CreatedAtAction(nameof(GetInvoice), new { invoiceNumber = invoiceToCreate.InvoiceNumber }, invoiceToCreate));
            }
            catch (Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "Error creating a new invoice"));
            }
        }
コード例 #6
0
        public async Task <HttpResponseMessage> Post([FromBody] Invoice order)
        {
            await _invoiceRepository.AddInvoice(order);

            var     t = CreatedAtAction("Get", new { id = order.OrderRef }, order);
            Invoice x = (Invoice)t.Value;
            var     r = x.getReady();


            var content = new FormUrlEncodedContent(r);

            return(await client.PostAsync("https://enigmatic-cove-40131.herokuapp.com/message/", content));
        }
コード例 #7
0
        public async Task <IActionResult> EndBooking(int id)
        {
            RentalAsset rentalAsset = await _rentalAssetRepository.GetItemByIdAsync(id);

            ActiveLease activeLease = _activeLeaseRepository.GetActiveLeaseByAssetId(rentalAsset.RentalAssetId);

            Lease lease = await _leaseRepository.GetLeaseById(activeLease.LeaseId);

            ApplicationUser user = await _userManager.FindByIdAsync(lease.UserId);

            if (rentalAsset == null)
            {
                ViewBag.ErrorMessage = $"The rental asset id={id} cannot be found";
                return(View("NotFound"));
            }
            else
            {
                try
                {
                    if (rentalAsset.BookTillDate < DateTime.Now)
                    {
                        // Calculate amount paid

                        var     totalDays  = (lease.leaseTo - lease.leaseFrom).TotalDays;
                        decimal AmountPaid = rentalAsset.Price * (decimal)totalDays;

                        //Add invoice
                        var invoice = new Invoice
                        {
                            RentalAssetId = rentalAsset.RentalAssetId,
                            LeaseFrom     = lease.leaseFrom,
                            LeaseTo       = lease.leaseTo,
                            ApplicationId = user.Id,
                            AmountPaid    = AmountPaid
                        };

                        await _invoiceRepository.AddInvoice(invoice);
                    }
                    await _rentalAssetRepository.EndBooking(id);

                    await _activeLeaseRepository.RemoveLease(activeLease);

                    return(RedirectToAction("BookedList"));
                }
                catch (Exception ex)
                {
                    return(NotFound(ex.Message));
                }
            }
        }
コード例 #8
0
        public async Task <IActionResult> AddInvoice([FromBody] InvoiceRequestViewModel invoice)
        {
            try
            {
                await _invoiceRepository.AddInvoice(invoice.ToInvoice());
            }
            catch (Exception)
            {
                return(Conflict(new ErrorResponseViewModel {
                    Id = (int)ErrorResponseIds.InvoiceAlreadyExist, Message = "Invoice already added"
                }));
            }

            return(Ok(true));
        }
コード例 #9
0
        public async Task <IActionResult> AddInvoice([FromBody] InvoiceResource saveInvoice)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var Invoice = mapper.Map <InvoiceResource, Invoice>(saveInvoice);

            InvoiceRepository.AddInvoice(Invoice);
            await unitOfWork.CompleteAsync();

            var InvoiceResource = mapper.Map <Invoice, InvoiceResource>(Invoice);

            return(Ok(InvoiceResource));
        }
コード例 #10
0
        public ActionResult <NewInvoiceDto> CreateInvoice(NewInvoiceDto newInvoiceDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(new ResponseDto <NewInvoiceDto>()
                {
                    message = ErrorMessage.InvalidModel
                }));
            }

            try
            {
                string role = HttpContext.GetUserRole();
                if (!(role == RoleNames.LaundryEmployee || role == RoleNames.LaundryOwner))
                {
                    return(BadRequest(new ResponseDto <string> {
                        statusCode = "401"
                    }));
                }

                InvoiceDto invoiceDto = invoiceRepository.AddInvoice(newInvoiceDto, role, HttpContext.User.Identity.Name);
                return(CreatedAtAction(nameof(ReadInvoice), new { id = invoiceDto.Id }, invoiceDto));
            }
            catch (Exception e)
            {
                if (e.Message == ErrorMessage.EntityDoesNotExist)
                {
                    return(BadRequest(new ResponseDto <InvoiceDto>()
                    {
                        message = "Customer does not exist"
                    }));
                }

                else if (e.Message == ErrorMessage.InvalidToken)
                {
                    return(BadRequest(new ResponseDto <InvoiceDto>()
                    {
                        message = "Customer was is not in users laundry"
                    }));
                }

                //if you got this point some unforseen error occured
                return(StatusCode(500));
            }
        }
コード例 #11
0
        public IActionResult Main(DashboardViewModel dvm)
        {
            var zone       = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");
            var utcNow     = DateTime.UtcNow;
            var pacificNow = TimeZoneInfo.ConvertTimeFromUtc(utcNow, zone);

            dvm.NewInvoice.StartDate = pacificNow;
            if (ModelState.IsValid)
            {
                dvm.NewInvoice.StatusId       = GetPendingStatusId().Result.StatusId;
                dvm.NewInvoice.NumberOfParts  = dvm.NumberOfPartsInVM.Value;
                dvm.NewInvoice.PickLocationId = dvm.PickLocationIdInVM.Value;

                //check if offsite, assign to offsite employee
                //should probably make this call async
                if (dvm.NewInvoice.PickLocationId == GetOffsitePickLocationId())
                {
                    dvm.NewInvoice.AssignedEmployeeId = GetOffsiteEmployeeId();
                }


                if (dvm.NewInvoice.AssignedEmployeeId != null)
                {
                    dvm.NewInvoice.AssignedDate = pacificNow;
                }

                _invoiceRepository.AddInvoice(dvm.NewInvoice);

                TempData["Message"] = "Invoice created successfully.";

                return(RedirectToAction("Main"));
            }

            dvm.Employees             = PopulateEmployeeSelectListOnsite();
            dvm.PickLocations         = GetPickLocations();
            dvm.ListOfInvoicesOnsite  = GetOnsiteInvoices();
            dvm.ListOfInvoicesOffsite = GetOffsiteInvoices();
            return(View(dvm));
        }
コード例 #12
0
        public ContentResult ConcreteTask(TaskViewModel taskViewModel, bool isSure)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(TaskViewModel));
            var           writer     = new StringWriter();

            serializer.Serialize(writer, taskViewModel);
            var xmlString = writer.ToString();

            try
            {
                _invoiceRepository.AddInvoice(new InvoiceData {
                    InvoiceXML = xmlString
                });
            }
            catch (Exception ex)
            {
                _logger.LogError("Cannot add invoice date to database!", ex);
            }
            return(new ContentResult
            {
                Content = xmlString
            });
        }
コード例 #13
0
 public OkResult Post()
 {
     _invoiceRepository.AddInvoice(new Invoice(Guid.NewGuid(), "sup", 200));
     return(Ok());
 }
コード例 #14
0
        //Get Customer Invoices
        private string GetInvoices(Customer customer, int customerId, QuickBooksOnlineConnectionStringBuilder connString)
        {
            _logger.LogInfo("Start Add or update invoice operation for customer for customer id " + customerId + " for subscriber id " + subscriberId);
            // Need to clear the list
            invoiceList = new List <Invoice>();
            // To insert error log in catch statement, made this variable public
            currentMethodName = this.ControllerContext.RouteData.Values["action"].ToString();
            bool     addInvoice = false;
            int      CustId;
            string   QBIId;
            int      colIndex = 0;
            string   IDNbr    = "";
            DateTime IDate;
            DateTime IDueDate;
            Decimal  ITotalAmt;
            Decimal  IBalance;
            string   ITxns;

            try
            {
                using (QuickBooksOnlineConnection connInv = new QuickBooksOnlineConnection(connString.ToString()))
                {
                    connInv.RuntimeLicense = runTimeLicense;
                    using (QuickBooksOnlineCommand cmdInv = new QuickBooksOnlineCommand("Select * FROM Invoices WHERE CustomerRef = " + customer.QBCustomerId, connInv))
                    {
                        using (QuickBooksOnlineDataReader reader = cmdInv.ExecuteReader())
                        {
                            DateTime ILastPymtDate = DateTime.MaxValue;
                            DateTime ILastReminder = DateTime.MaxValue;
                            while (reader.Read())
                            {
                                //if (Int32.TryParse((string)reader["Id"], out int IId))
                                //{
                                //}
                                //else
                                //{
                                //    continue;
                                //}
                                QBIId     = reader.GetString("Id");
                                CustId    = customerId;
                                colIndex  = reader.GetOrdinal("DocNumber");
                                IDNbr     = reader.GetString(colIndex);
                                IDate     = reader.GetDateTime("TxnDate");
                                IDueDate  = reader.GetDateTime("DueDate");
                                ITotalAmt = reader.GetDecimal("TotalAmt");
                                IBalance  = reader.GetDecimal("Balance");
                                colIndex  = reader.GetOrdinal("LinkedTxnAggregate");
                                ITxns     = Validate.SafeGetString(reader, colIndex);
                                //Filter Invoices to keep
                                addInvoice = false;
                                if (IBalance > 0)
                                {
                                    // we always want to add the invoice if the balance > 0
                                    addInvoice = true;
                                }
                                // Get the last payment date
                                XmlDocument xDoc = new XmlDocument();
                                // Convert string to stream
                                byte[]       byteArray = Encoding.ASCII.GetBytes(ITxns);
                                MemoryStream stream    = new MemoryStream(byteArray);
                                if (stream.Length > 0)
                                {
                                    xDoc.Load(stream);
                                    XmlNodeList xnList = xDoc.SelectNodes("/LinkedTxnAggregate/Row");
                                    // If we have transaction information, process it
                                    if (xnList.Count > 0)
                                    {
                                        foreach (XmlNode xn in xnList)
                                        {
                                            string txnId   = xn["TxnId"].InnerXml;
                                            string txnType = xn["TxnType"].InnerXml;
                                            if (txnType == "Payment")
                                            {
                                                DateTime txnDate = GetPymtDate(txnId, connString, IDNbr);
                                                DateTime now     = DateTime.Now;
                                                //for test data
                                                //DateTime now = new DateTime(2014, 12, 31);
                                                int monthDiff = GetMonthDifference(now, txnDate);
                                                if (monthDiff < 6)
                                                {
                                                    ILastPymtDate = txnDate;
                                                    addInvoice    = true;
                                                    break;
                                                }
                                                else
                                                {
                                                    if (addInvoice == true)
                                                    {
                                                        //Balance is greater than zero
                                                        //Add the invoice
                                                        ILastPymtDate = txnDate;
                                                    }
                                                    else
                                                    {
                                                        addInvoice = false;
                                                    }
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                }
                                // Don't add the invoice
                                if (addInvoice == false)
                                {
                                    continue;
                                }

                                invoiceList.Add(new Invoice
                                {
                                    InvoiceId        = 0,
                                    QBInvoiceId      = QBIId,
                                    CustomerId       = CustId,
                                    InvDocNbr        = IDNbr,
                                    InvDate          = IDate,
                                    InvDueDate       = IDueDate,
                                    InvTotalAmt      = ITotalAmt,
                                    InvBalance       = IBalance,
                                    InvTxns          = ITxns,
                                    InvLastPymtDate  = ILastPymtDate,
                                    InvLastReminder  = ILastReminder,
                                    SendAutoReminder = true
                                });
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.LogError("error occurred at invoice level" + ex.Message);
                _errorLogRepo.InsertErrorLog(new ErrorLog
                {
                    SubscriberId  = subscriberId,
                    ErrorMessage  = ex.Message,
                    InvDocNbr     = IDNbr,
                    ServiceName   = serviceName,
                    MethodName    = currentMethodName,
                    ErrorDateTime = DateTime.Now
                });
                return("Error occurred " + ex.Message);
            }

            foreach (var inv in invoiceList)
            {
                Invoice invoice = _invoiceRepo.GetByID(inv.CustomerId, inv.QBInvoiceId);
                if (invoice == null)
                {
                    // Need to add a invoice record
                    var result = _invoiceRepo.AddInvoice(inv);
                    if (result == false)
                    {
                        return("Not able to add Invoice.");
                    }
                }
                else
                {
                    // Need to update invoice
                    inv.InvoiceId = invoice.InvoiceId;
                    var result = _invoiceRepo.UpdateInvoice(inv);
                    if (result == false)
                    {
                        return("Not able to update Invoice.");
                    }
                }
            }
            _logger.LogInfo("End Add or update invoice operation for customer for customer id " + customerId + " for subscriber id " + subscriberId);
            return(SuccessMessage);
        }
コード例 #15
0
 public void AddInvoice(Invoice invoice)
 {
     _repository.AddInvoice(invoice);
 }
コード例 #16
0
 public IActionResult AddInvoice(Invoice model)
 {
     _invoiceRepo.AddInvoice(model);
     return(RedirectToAction(nameof(Index)));
 }