Exemplo n.º 1
0
        public IHttpActionResult GetAllEmployesReport(int?EmpId, int?ClientId, int?DoctorId, string JobWorkLevel, DateTime?fromdate, DateTime?todate, int?page, int?count, string sortCol, string sortDir)
        {
            try
            {
                using (MaxDbEntities db = new MaxDbEntities())
                {
                    var MtDirect = 0;
                    var MT       = 0;
                    var AQA      = 0;
                    var QA       = 0;

                    //TotalCharacterCountDetails totalCharacterCount = new TotalCharacterCountDetails();

                    var empReport = db.MaxEmpReport(EmpId, ClientId, DoctorId, JobWorkLevel, fromdate, todate, page, count, sortCol, sortDir).ToList();

                    foreach (var job in empReport)
                    {
                        switch (job.JobWorkLevel)
                        {
                        case "MT - Direct":
                            MtDirect += Convert.ToInt32(job.TotalCharacters);
                            break;

                        case "MT":
                            MT += Convert.ToInt32(job.TotalCharacters);
                            break;

                        case "AQA":
                            AQA += Convert.ToInt32(job.TotalCharacters);
                            break;

                        case "QA":
                            QA += Convert.ToInt32(job.TotalCharacters);
                            break;
                        }
                    }
                    int totalCount = 0;
                    if (empReport.Count > 0)
                    {
                        totalCount = (int)empReport.FirstOrDefault().TotalCount;
                    }
                    //totalCharacterCount.TotalMtDirect = MtDirect;
                    //totalCharacterCount.TotalMt = MT;
                    //totalCharacterCount.TotalAQA = AQA;
                    //totalCharacterCount.TotalQA = QA;
                    return(Content(HttpStatusCode.OK, new { empReport, totalCount }));
                }
            }
            catch (Exception ex)
            {
                new Error().logAPIError(System.Reflection.MethodBase.GetCurrentMethod().Name, ex.ToString(), ex.StackTrace);
                return(Content(HttpStatusCode.InternalServerError, "An error occoured, please try again!"));
            }
        }
Exemplo n.º 2
0
 public IHttpActionResult GetClientInvoice(int ClientId, DateTime fromDate)
 {
     try
     {
         using (MaxDbEntities db = new MaxDbEntities())
         {
             var InvoiceCount = db.DeletedInvoices.Where(inv => inv.Client_Id == ClientId && inv.InvoiceCreatedDate.Value.Month == fromDate.Month).Count();
             return(Content(HttpStatusCode.OK, new { InvoiceCount }));
         }
     }
     catch (Exception ex)
     {
         new Error().logAPIError(System.Reflection.MethodBase.GetCurrentMethod().Name, ex.ToString(), ex.StackTrace);
         return(Content(HttpStatusCode.InternalServerError, "An error occoured, please try again!"));
     }
 }
Exemplo n.º 3
0
 public IHttpActionResult GetPaymentDetails(int client_id)
 {
     try
     {
         using (MaxDbEntities db = new MaxDbEntities())
         {
             var paymentDetails = db.ClientPayments(client_id).ToList();
             return(Content(HttpStatusCode.OK, new { paymentDetails }));
         }
     }
     catch (Exception ex)
     {
         new Error().logAPIError(System.Reflection.MethodBase.GetCurrentMethod().Name, ex.ToString(), ex.StackTrace);
         return(InternalServerError());
     }
 }
Exemplo n.º 4
0
 public IHttpActionResult GetClientsCurrency(int ClientId)
 {
     try
     {
         using (MaxDbEntities db = new MaxDbEntities())
         {
             var client = db.MaxClientGet(ClientId).FirstOrDefault();
             return(Content(HttpStatusCode.OK, new { client }));
         }
     }
     catch (Exception ex)
     {
         new Error().logAPIError(System.Reflection.MethodBase.GetCurrentMethod().Name, ex.ToString(), ex.StackTrace);
         return(InternalServerError());
     }
 }
Exemplo n.º 5
0
        public IHttpActionResult GetAllClients()
        {
            try
            {
                using (MaxDbEntities db = new MaxDbEntities())
                {
                    var ClientNames = (from client in db.Clients select new { label = client.ShortName, value = client.Id }).OrderBy(x => x.label).ToList();

                    return(Content(HttpStatusCode.OK, new { ClientNames }));
                }
            }
            catch (Exception ex)
            {
                new Error().logAPIError(System.Reflection.MethodBase.GetCurrentMethod().Name, ex.ToString(), ex.StackTrace);
                return(Content(HttpStatusCode.InternalServerError, "An error occoured, please try again!"));
            }
        }
 public IHttpActionResult updateInvoice(string InvoiceId)
 {
     try
     {
         var form         = HttpContext.Current.Request.Form;
         var approvedBy   = form.Get("ApprovedBy");
         var approvedDate = form.Get("approvedDate");
         using (MaxDbEntities db = new MaxDbEntities())
         {
             var invoices = db.Invoices.First(x => x.Id == InvoiceId);
             invoices.InvoiceApprovedBy = (from emp in db.Employees where emp.EmployeeNumber == approvedBy select emp.Id).FirstOrDefault();
             invoices.ApprovedDate      = DateTime.Now;
             db.Entry(invoices).State   = System.Data.Entity.EntityState.Modified;
             db.SaveChanges();
         }
         return(Ok());
     }
     catch (Exception ex)
     {
         new Error().logAPIError(System.Reflection.MethodBase.GetCurrentMethod().Name, ex.ToString(), ex.StackTrace);
         return(InternalServerError());
     }
 }
        public IHttpActionResult AddInvoice()
        {
            try
            {
                InvoiceModel invoice = new InvoiceModel();

                var form           = HttpContext.Current.Request.Form;
                var clientId       = form.Get("Client_Id");
                var companyAddress = form.Get("CompanyAddress");
                var clientAddress  = form.Get("ClientAddress");
                var invoiceDate    = form.Get("InvoiceDate");
                var invoiceTime    = form.Get("InvoiceTime");
                var dueAmount      = form.Get("UnpaidBalance");
                if (dueAmount == "null")
                {
                    dueAmount = 0.ToString();
                }
                var CurrentAmount = form.Get("CurrentAmount");
                var totalLines    = form.Get("TotalLines");
                var status        = form.Get("Status");
                var serviceId     = form.Get("ClientService");
                var unitPrice     = form.Get("UnitPrice");
                var invoiceId     = form.Get("InvoiceId");
                var createdBy     = form.Get("CreatedBy");
                var invoiceSer    = JsonConvert.DeserializeObject <List <string> >(form.Get("InvoiceServices"));

                using (MaxDbEntities db = new MaxDbEntities())

                {
                    Invoice        inData    = new Invoice();
                    InvoiceService inService = new InvoiceService();

                    inData.Client_Id          = Convert.ToInt32(clientId);
                    inData.Id                 = invoiceId;
                    inData.CompanyAddress     = companyAddress;
                    inData.ClientAddress      = clientAddress;
                    inData.InvoiceCreatedBy   = (from Emp in db.Employees where Emp.EmployeeNumber == createdBy select Emp.Id).FirstOrDefault();
                    inData.InvoiceCreatedDate = Convert.ToDateTime(invoiceDate);

                    string currency = (from client in db.Clients where client.Id == inData.Client_Id select client.Currency).FirstOrDefault();
                    inData.CurrencyType = currency;

                    inData.CurrentBillAmount  = Convert.ToDecimal(CurrentAmount);
                    inData.TotalDueAmount     = Convert.ToDecimal(dueAmount);
                    inData.TotalInvoiceAmount = Convert.ToDecimal(CurrentAmount);

                    foreach (string id in invoiceSer)
                    {
                        string unitprice = (from client in db.Clients where client.Id == inData.Client_Id select client.PaymentAmount).FirstOrDefault().ToString();

                        inService.InvoiceId  = inData.Id;
                        inService.ClientId   = Convert.ToInt32(clientId);
                        inService.ServiceId  = Convert.ToInt32(serviceId);
                        inService.UnitPrice  = Convert.ToDecimal(unitPrice);
                        inService.TotalLines = Convert.ToInt32(totalLines);
                        inService.BillAmount = Convert.ToDecimal(CurrentAmount);
                        inService.DueAmount  = inService.BillAmount;
                    }
                    db.Invoices.Add(inData);
                    db.InvoiceServices.Add(inService);
                    db.SaveChanges();
                }
                return(Ok());
            }
            catch (Exception ex)
            {
                new Error().logAPIError(System.Reflection.MethodBase.GetCurrentMethod().Name, ex.ToString(), ex.StackTrace);
                return(InternalServerError());
            }
        }
        public IHttpActionResult DeleteInvoice(string InvoiceId)
        {
            try
            {
                var form        = HttpContext.Current.Request.Form;
                var description = form.Get("Description");
                var invoiceId   = form.Get("InvoiceId");

                using (MaxDbEntities db = new MaxDbEntities())
                {
                    //var invoices = db.Invoices.Where(x => x.Id==InvoiceId).FirstOrDefault();
                    //var invoiceServices = db.InvoiceServices.Where(x => x.InvoiceId == InvoiceId).FirstOrDefault();

                    //  var deleteRecord = db.DeleteClientPayment(InvoiceId);

                    var invoiceSer = db.InvoiceServices.First(x => x.InvoiceId == InvoiceId);
                    var Inv        = db.Invoices.First(x => x.Id == InvoiceId);

                    if (InvoiceId == null)
                    {
                        return(Content(HttpStatusCode.InternalServerError, "Invalid data, please try again!"));
                    }

                    if (invoiceSer.PaymentId == null)
                    {
                        DeletedInvoice        Di    = new DeletedInvoice();
                        DeletedInvoiceService DInvs = new DeletedInvoiceService();

                        Di.Id                 = Inv.Id;
                        Di.ApprovedDate       = Inv.ApprovedDate;
                        Di.ClientAddress      = Inv.ClientAddress;
                        Di.Client_Id          = Inv.Client_Id;
                        Di.CompanyAddress     = Inv.CompanyAddress;
                        Di.CurrencyType       = Inv.CurrencyType;
                        Di.CurrentBillAmount  = Inv.CurrentBillAmount;
                        Di.InvoiceApprovedBy  = Inv.InvoiceApprovedBy;
                        Di.ApprovedDate       = Inv.ApprovedDate;
                        Di.InvoiceCreatedBy   = Inv.InvoiceCreatedBy;
                        Di.InvoiceCreatedDate = Inv.InvoiceCreatedDate;
                        Di.InvoiceURL         = Inv.InvoiceURL;
                        Di.Status             = Inv.Status;
                        Di.TotalDueAmount     = Inv.TotalDueAmount;
                        Di.TotalInvoiceAmount = Inv.TotalInvoiceAmount;
                        Di.Description        = description;

                        DInvs.AmountPaidDate = invoiceSer.AmountPaidDate;
                        DInvs.BillAmount     = invoiceSer.BillAmount;
                        DInvs.ClientId       = invoiceSer.ClientId;
                        DInvs.DueAmount      = invoiceSer.DueAmount;
                        DInvs.InvoiceId      = invoiceSer.InvoiceId;
                        DInvs.PaymentId      = invoiceSer.PaymentId;
                        DInvs.ServiceId      = invoiceSer.ServiceId;
                        DInvs.Id             = invoiceSer.Id;

                        db.DeletedInvoices.Add(Di);
                        db.DeletedInvoiceServices.Add(DInvs);

                        db.InvoiceServices.Remove(invoiceSer);
                        db.Invoices.Remove(Inv);
                        db.SaveChanges();
                    }
                    return(Ok());
                }
            }
            catch (Exception ex)
            {
                new Error().logAPIError(System.Reflection.MethodBase.GetCurrentMethod().Name, ex.ToString(), ex.StackTrace);
                return(InternalServerError());
            }
        }
        public async Task <IHttpActionResult> PayAmount()
        {
            try
            {
                var form = HttpContext.Current.Request.Form;

                var clientId        = form.Get("Client_Id");
                var TotalamountPaid = form.Get("paymentAmount");
                var paymentDate     = form.Get("paymentDate");
                var currency        = form.Get("Currency");
                var description     = form.Get("Description");

                var invoiceServiceIds = JsonConvert.DeserializeObject <List <string> >(form.Get("ClientPayment"));

                var file      = HttpContext.Current.Request.Files;
                var ChequePdf = file["ChequePdf"];

                if (ChequePdf != null)
                {
                    var fileExtension   = Path.GetExtension(ChequePdf.FileName);
                    var validExtensions = new string[] { ".doc", ".docx", ".pdf", ".txt" };

                    if (!validExtensions.Contains(fileExtension))
                    {
                        return(Content(HttpStatusCode.InternalServerError, "Invalid file type for resume!!"));
                    }
                }


                using (MaxDbEntities db = new MaxDbEntities())
                {
                    var invoiceServices = db.InvoiceServices.Where(x => invoiceServiceIds.Contains(x.InvoiceId)).OrderByDescending(x => x.InvoiceId);

                    ClientReceivable clientRecv = new ClientReceivable();

                    clientRecv.Client_Id   = Convert.ToInt32(clientId);
                    clientRecv.Currency    = currency;
                    clientRecv.PaymentDate = Convert.ToDateTime(paymentDate);
                    clientRecv.Description = description;
                    clientRecv.AmountPaid  = Convert.ToDecimal(TotalamountPaid);

                    var files           = HttpContext.Current.Request.Files;
                    var ScannedDocument = files["ChequePdf"];
                    if (ScannedDocument != null)
                    {
                        var fileDirecory = HttpContext.Current.Server.MapPath("~/ClientCheque");
                        if (!Directory.Exists(fileDirecory))
                        {
                            Directory.CreateDirectory(fileDirecory);
                        }
                        var fileName = DateTime.Now.Ticks + "_" + ScannedDocument.FileName;
                        var filepath = Path.Combine(fileDirecory, fileName);
                        ScannedDocument.SaveAs(filepath);
                        clientRecv.ScannedDocument = Path.Combine(ConfigurationManager.AppSettings["ApiUrl"], "ClientCheque", fileName);
                    }

                    var totalAmountAvailable = Convert.ToDecimal(TotalamountPaid);

                    foreach (string id in invoiceServiceIds)
                    {
                        var invoiceService = db.InvoiceServices.Where(x => x.InvoiceId == id).FirstOrDefault();
                        ClientReceivableService clientSer = new ClientReceivableService();

                        clientSer.Description = description;
                        clientSer.ServiceId   = invoiceService.Id;

                        if (totalAmountAvailable > 0)
                        {
                            if (Convert.ToDecimal(totalAmountAvailable) > Convert.ToDecimal(invoiceService.DueAmount))
                            {
                                totalAmountAvailable    -= Convert.ToDecimal(invoiceService.DueAmount);
                                clientSer.PaidAmount     = invoiceService.DueAmount;
                                invoiceService.DueAmount = 0;
                            }

                            else
                            {
                                invoiceService.DueAmount = invoiceService.DueAmount - totalAmountAvailable;
                                clientSer.PaidAmount     = Convert.ToDecimal(totalAmountAvailable);
                                clientRecv.Balance       = 0;
                                totalAmountAvailable     = 0;
                            }

                            clientRecv.Balance = totalAmountAvailable;
                        }

                        else
                        {
                            invoiceService.DueAmount = Convert.ToDecimal(invoiceService.DueAmount);
                            clientSer.PaidAmount     = 0;
                        }

                        invoiceService.AmountPaidDate = Convert.ToDateTime(paymentDate);
                        clientSer.ClientReceivable    = clientRecv;
                        db.ClientReceivableServices.Add(clientSer);
                        invoiceService.ClientReceivable = clientRecv;
                        db.Entry(invoiceService).State  = System.Data.Entity.EntityState.Modified;
                    }

                    db.ClientReceivables.Add(clientRecv);
                    db.SaveChanges();
                }
                return(Ok());
            }

            catch (Exception ex)
            {
                new Error().logAPIError(System.Reflection.MethodBase.GetCurrentMethod().Name, ex.ToString(), ex.StackTrace);
                return(InternalServerError());
            }
        }
Exemplo n.º 10
0
        public IHttpActionResult GetClientReport(int?clientId, int?page, int?count, DateTime?fromdate, DateTime?todate, string SortCol, string SortDir)
        {
            try
            {
                using (MaxDbEntities db = new MaxDbEntities())
                {
                    int totalCount   = 0;
                    var clientReport = db.MaxClientReport(clientId, page, count, fromdate, todate, SortCol, SortDir).ToList();

                    if (clientReport.Count > 0)
                    {
                        totalCount = (int)clientReport.FirstOrDefault().TotalCount;
                    }
                    List <ClientsViewModel> clients   = new List <ClientsViewModel>();
                    TotalCountOfCharacters  totalChar = new TotalCountOfCharacters();
                    int clientCount = clientReport.Count();

                    foreach (var client in clientReport)
                    {
                        ClientsViewModel clientView = new ClientsViewModel();

                        clientView.ClientId  = client.Id;
                        clientView.ShortName = client.ShortName;
                        clientView.NumberOfCharactersPerLine = Convert.ToInt32(client.NumberOfCharactersPerLine);
                        clientView.AmountPerUnit             = Convert.ToDecimal(client.PaymentAmount);
                        clientView.Currency = client.Currency;

                        clientView.RowNum            = Convert.ToInt32(client.RowNum);
                        clientView.LineCount_55      = Convert.ToInt32(client.LineCount_55);
                        totalChar.TotalCharCount_55 += clientView.LineCount_55;

                        clientView.LineCount_60      = Convert.ToInt32(client.LineCount_60);
                        totalChar.TotalCharCount_60 += clientView.LineCount_60;

                        clientView.LineCount_65      = Convert.ToInt32(client.LineCount_65);
                        totalChar.TotalCharCount_65 += clientView.LineCount_65;

                        clientView.ClientLineCount = Convert.ToInt32(client.ActualLineCount);
                        clientView.TotalJobs       = Convert.ToInt32(client.TotalJobs);
                        clientView.EmptyJobs       = Convert.ToInt32(client.EmptyJobs);
                        clientView.PaymentType     = client.PaymentType;

                        bool InvoiceGenerated = db.Invoices.Any(x => x.Client_Id == client.Id && x.InvoiceCreatedDate.Value.Month == fromdate.Value.Month);
                        clientView.InvoiceGenerated = InvoiceGenerated;

                        clientView.TotalMinutes = new TimeSpan(0, Convert.ToInt32(client.TotalMinutes), 0);
                        totalChar.TotalMinutes += clientView.TotalMinutes;

                        if (clientView.PaymentType == "Per Unit")
                        {
                            clientView.PaymentAmount = Convert.ToDecimal(client.PaymentAmount * client.ActualLineCount);
                        }
                        else if (clientView.PaymentType == "Fixed")
                        {
                            clientView.PaymentAmount = Convert.ToDecimal(client.PaymentAmount);
                        }
                        clients.Add(clientView);
                    }
                    return(Content(HttpStatusCode.OK, new { clients, totalCount, totalChar.TotalCharCount_60, totalChar.TotalCharCount_55, totalChar.TotalCharCount_65, totalChar.TotalMinutes }));
                }
            }
            catch (Exception ex)
            {
                new Error().logAPIError(System.Reflection.MethodBase.GetCurrentMethod().Name, ex.ToString(), ex.StackTrace);
                return(Content(HttpStatusCode.InternalServerError, "An error occoured, please try again!"));
            }
        }
Exemplo n.º 11
0
        public ActionResult GetInvoiceDetails(int ClientId, DateTime?fromdate, DateTime?todate)
        {
            try
            {
                using (MaxDbEntities db = new MaxDbEntities())
                {
                    var          clientDetails   = db.MaxClient_Details(ClientId, fromdate, todate).ToList();
                    var          clientDueAmount = db.MaxClientDueDetails(ClientId).FirstOrDefault();
                    InvoiceModel invoice         = new InvoiceModel();

                    if (clientDueAmount == null)
                    {
                        invoice.DueAmount = 0;
                    }
                    else
                    {
                        invoice.DueAmount = Math.Round(Convert.ToDecimal(clientDueAmount.DueAmount));
                    }

                    List <InvoiceModel> invoices = new List <InvoiceModel>();

                    foreach (var client in clientDetails)
                    {
                        // InvoiceModel invoice = new InvoiceModel();
                        invoice.Client_Id       = client.Client_Id;
                        invoice.Client_Name     = client.ClientName;
                        invoice.ClientShortName = client.ShortName;
                        invoice.Address         = client.AddressLine1;
                        invoice.ServiceType     = client.ServiceType;
                        invoice.ServiceId       = Convert.ToInt32(client.ClientVertical_Id);
                        invoice.PaymentType     = client.PaymentType;
                        invoice.RowNum          = Convert.ToInt32(client.RowNum);
                        invoice.LineCount       = Convert.ToInt32(client.LineCount);
                        invoice.CountryName     = client.Name;
                        if (client.PaymentType == "Per Unit")
                        {
                            invoice.UnitPrice           = Convert.ToDecimal(client.PaymentAmount);
                            invoice.UnitPriceforDisplay = (client.PaymentAmount).ToString();
                            invoice.Amount = Math.Round(Convert.ToDecimal(client.LineCount * client.PaymentAmount));
                        }
                        if (client.PaymentType == "Fixed")
                        {
                            invoice.UnitPriceforDisplay = "Fixed";
                            invoice.UnitPrice           = Convert.ToDecimal(client.PaymentAmount);
                            invoice.Amount = Math.Round(Convert.ToDecimal(client.PaymentAmount));
                        }

                        invoice.TotalAmount = Math.Round(Convert.ToDecimal(invoice.Amount + invoice.DueAmount));

                        invoice.MonthYear = fromdate.Value.ToString("MMMM yyyy");
                        invoices.Add(invoice);
                    }

                    invoice.InvoiceDate        = fromdate.Value.ToShortDateString();
                    invoice.InvoiceDueDate     = fromdate.Value.AddDays(10).ToShortDateString();
                    invoice.InvoiceCurrentDate = DateTime.Now.ToShortDateString();

                    var InvoiceCount = db.DeletedInvoices.Where(inv => inv.Client_Id == ClientId && inv.InvoiceCreatedDate.Value.Month == fromdate.Value.Month).Count();
                    int count        = Convert.ToInt32(InvoiceCount);

                    invoice.InvoiceNumber = "MAX-" + invoice.Client_Id + (fromdate.Value.Month).ToString().Substring(0, 1) + (fromdate.Value.Year).ToString().Substring(2, 2) + "_" + ++count;

                    string    html      = RenderRazorViewToString("GetInvoiceDetails", invoice);
                    string    baseUrl   = System.Web.HttpContext.Current.Request.Url.AbsoluteUri;
                    HtmlToPdf converter = new HtmlToPdf();

                    converter.Options.DisplayFooter = true;
                    string         footerUrl  = Server.MapPath("~/views/home/footer.html");
                    PdfHtmlSection footerHtml = new PdfHtmlSection(footerUrl);
                    footerHtml.AutoFitHeight = HtmlToPdfPageFitMode.AutoFit;
                    converter.Footer.Add(footerHtml);

                    PdfDocument doc = converter.ConvertHtmlString(html, baseUrl);

                    // save pdf document
                    byte[] pdf = doc.Save();

                    // close pdf document
                    doc.Close();

                    // return resulted pdf document
                    FileResult fileResult = new FileContentResult(pdf, "application/pdf");
                    fileResult.FileDownloadName = invoice.InvoiceNumber + "_" + invoice.ClientShortName + ".pdf";
                    return(fileResult);
                    //return View(invoice);
                }
            }
            catch (Exception ex)
            {
                new Error().logAPIError(System.Reflection.MethodBase.GetCurrentMethod().Name, ex.ToString(), ex.StackTrace);
                return(View());
            }
        }