Ejemplo n.º 1
0
        public ActionResult SaveModelData(tblPerformaInvoice model, string create = null)
        {
            if (!ModelState.IsValid)
            {
                return(View("Create", model));
            }

            string message = string.Empty;

            try
            {
                if (model.PerformaInvoiceId > 0)
                {
                    model.ModifiedBy   = SessionHelper.UserId;
                    model.ModifiedDate = DateTime.Now;
                    message            = _dbRepository.Update(model);
                }
                else
                {
                    model.CreatedBy   = SessionHelper.UserId;
                    model.CreatedDate = DateTime.Now;
                    message           = _dbRepository.Insert(model);
                }
            }
            catch (Exception ex)
            {
                message = CommonHelper.GetErrorMessage(ex);
            }

            if (model.PerformaInvoiceId > 0)
            {
                if (create == "Save & Continue")
                {
                    return(RedirectToAction("Edit", new { id = model.PerformaInvoiceId }));
                }
                else if (create == "Save & New")
                {
                    return(RedirectToAction("Create"));
                }
            }
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 2
0
        public ActionResult GeneratePIFromQuotation(int QuotationId, string SelectedIds = null)
        {
            if (QuotationId > 0)
            {
                tblMachinePartsQuotation quotationObj = _dbRepository.SelectById(QuotationId);
                if (quotationObj != null)
                {
                    List <int> selectedIDs = new List <int>();
                    List <tblMachinePartsQuotationDetail> detailObj = new List <tblMachinePartsQuotationDetail>();
                    if (!string.IsNullOrEmpty(SelectedIds))
                    {
                        selectedIDs = SelectedIds.Split(',').Select(int.Parse).ToList();
                    }
                    else
                    {
                        selectedIDs = _dbRepositoryDetail.GetEntities().Where(m => m.MachinePartsQuotationId == QuotationId).Select(m => m.MPQDetailId).ToList();
                    }

                    if (selectedIDs.Count > 0)
                    {
                        foreach (int id in selectedIDs)
                        {
                            tblMachinePartsQuotationDetail obj = _dbRepositoryDetail.SelectById(id);
                            detailObj.Add(obj);
                        }
                        if (detailObj.Count > 0)
                        {
                            tblPerformaInvoice invoiceObj = new tblPerformaInvoice();
                            invoiceObj.MPQuotationId             = quotationObj.MachinePartsQuotationId;
                            invoiceObj.QuotationNo               = quotationObj.QuotationNo;
                            invoiceObj.QuotationDate             = quotationObj.QuotationDate;
                            invoiceObj.CustomerId                = quotationObj.CustomerId;
                            invoiceObj.CustomerContactPId        = quotationObj.CustomerContactPId;
                            invoiceObj.CustomerContactPContactNo = quotationObj.CustomerContactPContactNo;
                            invoiceObj.ReportServiceNo           = quotationObj.ReportServiceNo;
                            invoiceObj.InquiryNo          = quotationObj.InquiryNo;
                            invoiceObj.InquiryDate        = quotationObj.InquiryDate;
                            invoiceObj.PaymentTerms       = quotationObj.PaymentTerms;
                            invoiceObj.DeliveryWeeks      = quotationObj.DeliveryWeeks;
                            invoiceObj.Insurance          = quotationObj.Insurance;
                            invoiceObj.ValidityDays       = quotationObj.ValidityDays;
                            invoiceObj.Email              = quotationObj.Email;
                            invoiceObj.TotalFinalAmount   = quotationObj.TotalFinalAmount;
                            invoiceObj.FreightAmount      = quotationObj.FreightAmount;
                            invoiceObj.QuotationAmount    = quotationObj.QuotationAmount;
                            invoiceObj.TotalFreightAmount = quotationObj.TotalFreightAmount;
                            invoiceObj.ServiceEngineerId  = quotationObj.ServiceEngineerId;
                            invoiceObj.FreightPercentage  = quotationObj.FreightPercentage;
                            invoiceObj.Remarks            = quotationObj.Remarks;
                            invoiceObj.SequenceNo         = quotationObj.SequenceNo;
                            invoiceObj.CreatedBy          = SessionHelper.UserId;
                            invoiceObj.CreatedDate        = DateTime.Now;
                            string result = _dbRepositoryPI.Insert(invoiceObj);
                            if (string.IsNullOrEmpty(result))
                            {
                                foreach (tblMachinePartsQuotationDetail obj in detailObj)
                                {
                                    tblPerformaInvoiceDetail piDetailObj = new tblPerformaInvoiceDetail();
                                    piDetailObj.PerformaInvoiceId      = invoiceObj.PerformaInvoiceId;
                                    piDetailObj.MPQDetailId            = obj.MPQDetailId;
                                    piDetailObj.MachineTypeId          = obj.MachineTypeId;
                                    piDetailObj.MachineModelId         = obj.MachineModelId;
                                    piDetailObj.MachineModelSerialNo   = obj.MachineModelSerialNo;
                                    piDetailObj.MachinePartsId         = obj.MachinePartsId;
                                    piDetailObj.MachinePartsNo         = obj.MachinePartsNo;
                                    piDetailObj.MachinePartDescription = obj.MachinePartDescription;
                                    piDetailObj.PartsHSNCode           = obj.PartsHSNCode;
                                    piDetailObj.PartsQuantity          = obj.PartsQuantity;
                                    piDetailObj.UnitPrice              = obj.UnitPrice;
                                    piDetailObj.TotalPrice             = obj.TotalPrice;
                                    piDetailObj.PAndFPercentage        = obj.PAndFPercentage;
                                    piDetailObj.ProfitMarginPercentage = obj.ProfitMarginPercentage;
                                    piDetailObj.DiscountPercentage     = obj.DiscountPercentage;
                                    piDetailObj.TaxablePrice           = obj.TaxablePrice;
                                    piDetailObj.GSTPercentage          = obj.GSTPercentage;
                                    piDetailObj.GSTAmount              = obj.GSTAmount;
                                    piDetailObj.FinalAmount            = obj.FinalAmount;
                                    piDetailObj.CreatedBy              = SessionHelper.UserId;
                                    piDetailObj.CreatedDate            = DateTime.Now;

                                    _dbRepositoryPIDetail.Insert(piDetailObj);
                                }

                                quotationObj.IsPIGenerated = true;
                                _dbRepository.Update(quotationObj);

                                return(RedirectToAction("Edit", "PI", new { id = invoiceObj.PerformaInvoiceId }));
                            }
                        }
                    }
                    else
                    {
                        TempData["Error"] = "There are no products to quoatation details. So please add products first.";
                        return(View("Index"));
                    }
                }
            }
            TempData["Error"] = "Something Went Wrong. Please try again later!";
            return(View("Index"));
        }