Exemple #1
0
        public void do_save()
        {
            try
            {
                bs_InvoiceOwner.EndEdit();
                bs_InvoiceTrans.EndEdit();

                if (do_Validation())
                {
                    return;
                }

                foreach (var item in __dll_List_InoviceTrans)
                {
                    if (_productlist.Where(x => x.PID == item.ProductId).FirstOrDefault().PFirstPrice.GetValueOrDefault() != item.BirimFiyat)
                    {
                        if (MspTool.get_Question("Birim Fiyatlarında Değişklikleri Mevcuttur. Değiştirilsin Mi?"))
                        {
                            BirimFiyatChance = true;
                        }
                    }
                }

                if (MspTool.get_Question("Kaydedilecektir Onaylıyor musunuz?"))
                {
                    __dll_InvoiceOwner.CompanyId = AppMain.CompanyRecId;
                    var req = new InvoiceSaveRequest()
                    {
                        InvoiceOwner     = __dll_InvoiceOwner,
                        InvoiceTrans     = __dll_List_InoviceTrans,
                        IsOrder          = _IsOrders,
                        _invoiceType     = (int)invoice,
                        BirimFiyatChance = BirimFiyatChance,
                    };
                    var response = _repository.Run <InvoiceService, ActionResponse <InvoiceSaveRequest> >(x => x.Save_Inovice(req));
                    if (response.ResponseType != ResponseType.Ok)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show(response.Message, "HATA", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    }
                    else
                    {
                        foreach (Form item in Application.OpenForms)
                        {
                            if (item.Name == "InvoiceList")
                            {
                                ((InvoiceList)item).do_refresh();
                            }
                        }
                        this.Close();
                    }
                }
            }
            catch (Exception)
            {
            }
        }
Exemple #2
0
 public IActionResult SaveInvoice([FromBody] InvoiceSaveRequest request)
 {
     try
     {
         _invoiceService.SaveInvoice(request, BranchId, UserId);
         return(Ok(HttpStatusCode.OK));
     }
     catch (Exception ex)
     {
         return(BadRequest(ex));
     }
 }
Exemple #3
0
        public ActionResponse <InvoiceSaveRequest> Save_Inovice(InvoiceSaveRequest model)
        {
            ActionResponse <InvoiceSaveRequest> response = new ActionResponse <InvoiceSaveRequest>()
            {
                Response     = model,
                ResponseType = ResponseType.Ok
            };

            using (MspDbContext _db = new MspDbContext())
            {
                using (DbContextTransaction transaction = _db.Database.BeginTransaction())
                {
                    try
                    {
                        if (_db.InvoiceOwner.Any(x => x.FicheDocumentNo == model.InvoiceOwner.FicheDocumentNo && x.RecId == 0 && x.Deleted == false))
                        {
                            response.Message      = "Aynı Fatura No'dan vardır.";
                            response.ResponseType = ResponseType.Error;
                            return(response);
                        }


                        int InvoiceOwnerRecId = 0;
                        if (response.Response.InvoiceOwner.RecId == 0)
                        {
                            InvoiceOwner invoiceOwner = base.Map <InvoiceOwnerDTO, InvoiceOwner>(model.InvoiceOwner);
                            _db.InvoiceOwner.Add(invoiceOwner);
                            _db.SaveChanges();
                            InvoiceOwnerRecId = invoiceOwner.RecId;
                        }
                        else
                        {
                            var entity = _db.InvoiceOwner.FirstOrDefault(x => x.RecId == response.Response.InvoiceOwner.RecId);
                            if (entity != null)
                            {
                                _db.Entry(entity).CurrentValues.SetValues(model.InvoiceOwner);
                                _db.Entry(entity).State = System.Data.Entity.EntityState.Modified;
                            }
                        }


                        foreach (var item in model.InvoiceTrans)
                        {
                            if (item.RecId == 0)
                            {
                                item.InvoiceOwnerId = InvoiceOwnerRecId;
                                _db.InvoiceTrans.Add(base.Map <InvoiceTransDTO, InvoiceTrans>(item));
                                var product = _db.products.FirstOrDefault(x => x.PID == item.ProductId);
                                if (product != null)
                                {
                                    Products updatePro = new Products();
                                    updatePro = product;
                                    if (model._invoiceType == 1)
                                    {
                                        updatePro.PTotal = updatePro.PTotal + item.Quentity;
                                        if (model.BirimFiyatChance)
                                        {
                                            updatePro.PFirstPrice = item.BirimFiyat;
                                        }
                                        base.Insert_ProductMovement("Alım Faturası", product.PID, item.Quentity.GetValueOrDefault(), item.BirimFiyat.GetValueOrDefault(), _db);
                                    }
                                    if (model._invoiceType == 2)
                                    {
                                        updatePro.PTotal = updatePro.PTotal - item.Quentity;
                                        base.Insert_ProductMovement("Satış Faturası", product.PID, item.Quentity.GetValueOrDefault(), item.BirimFiyat.GetValueOrDefault(), _db);
                                    }
                                    _db.Entry(product).CurrentValues.SetValues(updatePro);
                                    _db.Entry(product).State = System.Data.Entity.EntityState.Modified;
                                }
                            }
                            else
                            {
                                var entity = _db.InvoiceTrans.FirstOrDefault(x => x.RecId == item.RecId);
                                if (entity != null)
                                {
                                    _db.Entry(entity).CurrentValues.SetValues(item);
                                    _db.Entry(entity).State = System.Data.Entity.EntityState.Modified;
                                }
                            }
                        }

                        if (model.IsOrder)
                        {
                            var order = _db.OrderOwner.FirstOrDefault(x => x.RecId == response.Response.InvoiceOwner.OrderId);
                            if (order != null)
                            {
                                order.IrsaliyeId = InvoiceOwnerRecId;
                                order.Durum      = "İrsaliye Tarafında";
                                _db.Entry(order).CurrentValues.SetValues(order);
                                _db.Entry(order).State = EntityState.Modified;
                            }
                        }

                        _db.SaveChanges();
                        transaction.Commit();
                    }
                    catch (Exception e)
                    {
                        transaction.Rollback();
                        response.Message      = e.ToString();
                        response.ResponseType = ResponseType.Error;
                    }
                }
            }
            return(response);
        }
        public void SaveInvoice(InvoiceSaveRequest request, int branchId, int userId)
        {
            try
            {
                decimal treatmentsSubTotal = request.Treatments != null?request.Treatments.Sum(c => c.Price *c.Quantity) : 0.0M;

                // decimal treatmentsTax = (treatmentsSubTotal - request.TreatmentDiscount) * 0.06M;
                decimal treatmentsTax = treatmentsSubTotal * 0.06M;
                //decimal treatmentsDueAmount = treatmentsTax + (treatmentsSubTotal - request.TreatmentDiscount);
                decimal treatmentsDueAmount = treatmentsTax + treatmentsSubTotal;

                decimal productsSubTotal = request.Products != null?request.Products.Sum(c => c.Price *c.Quantity) : 0.0M;

                decimal productsTax       = (productsSubTotal) * 0.06M;
                decimal productsDueAmount = productsTax + productsSubTotal;

                var invoiceableTreatments = new List <CustomerInvoiceTreatment>();
                var invoiceableproducts   = new List <CustomerInvoiceProducts>();

                if (request.Treatments != null && request.Treatments.Count > 0)
                {
                    foreach (var treatment in request.Treatments)
                    {
                        invoiceableTreatments.Add(new CustomerInvoiceTreatment()
                        {
                            Qty   = treatment.Quantity,
                            Price = treatment.Price,
                            Cost  = treatment.Cost,
                            Ttid  = treatment.TreatmentTypeId,
                            Empno = treatment.EmployeeNo,
                            Cstid = treatment.CustomerScheduleTreatmentId,
                        });
                    }
                }

                if (request.Products != null && request.Products.Count > 0)
                {
                    foreach (var product in request.Products)
                    {
                        decimal subTotal = (product.Price * product.Quantity);
                        decimal tax      = (subTotal) * 0.06M;

                        invoiceableproducts.Add(new CustomerInvoiceProducts()
                        {
                            Qty       = product.Quantity,
                            Price     = product.Price,
                            Cost      = product.Cost,
                            Empno     = product.RecomendedBy,
                            ProductId = product.ProductId
                        });
                    }
                }

                string invoiceNo = GenerateInvoiceNo();

                var invoiceHeader = new CustomerInvoiceHeader()
                {
                    InvoiceNo                = invoiceNo,
                    BranchId                 = branchId,
                    EnteredBy                = userId,
                    EnteredDate              = DateTime.Now,
                    CustomerId               = request.CustomerId,
                    InvDateTime              = DateTime.Now,
                    TransType                = "Cash",
                    Ptid                     = 1,
                    DepartmentId             = request.DepartmentId,
                    IsCanceled               = false,
                    CustomerInvoiceProducts  = invoiceableproducts,
                    CustomerInvoiceTreatment = invoiceableTreatments,
                    TreatmentSubTotalAmount  = treatmentsSubTotal,
                    TreatmentDueAmount       = treatmentsDueAmount,
                    TreatmentTaxAmount       = treatmentsTax,
                    ProductSubTotalAmount    = productsSubTotal,
                    ProductDueAmount         = productsDueAmount,
                    ProductTaxAmount         = productsTax,
                    CCTId                    = request.CreditCardTypeId
                };

                _customerInvoiceHeaderRepository.Add(invoiceHeader);
                _customerInvoiceHeaderRepository.SaveChanges();
            }
            catch (Exception ex)
            {
                throw;
            }
        }