Пример #1
0
        public void Create(InvoiceDetailViewModel model)
        {
            var entity = mapper.Map(model, new InvoiceDetail());

            invoiceDetailRepository.Add(entity);
            invoiceDetailRepository.SaveChanges();
        }
Пример #2
0
        /// <summary>
        /// Save all invoices
        /// </summary>
        /// <param name="lst">invoices</param>
        /// <returns></returns>
        public ApiResponseViewModel SaveAll(List <InvoiceInput> lst)
        {
            var result   = new List <InvoiceDetail>();
            var response = new ApiResponseViewModel
            {
                Code    = CommonConstants.ApiResponseSuccessCode,
                Message = null,
                Result  = null
            };

            try
            {
                foreach (var item in lst)
                {
                    decimal totalValue  = 0;
                    var     customerID  = 0;
                    var     inOut       = false;
                    var     invoiceCode = "";
                    foreach (var sub in item.details)
                    {
                        var obj = new InvoiceDetail();
                        obj.ID           = 0;
                        obj.InvoiceID    = item.id;
                        obj.Value        = sub.Value;
                        obj.DepartmentID = sub.DepartmentID;
                        obj.CategoryID   = sub.CategoryID;
                        obj.TaxValueID   = sub.TaxValue;
                        obj.IsActive     = true;
                        obj.TaxValueID   = sub.TaxValue;
                        result.Add(_InvoiceDetailRepository.Add(obj));

                        totalValue += sub.Value;
                        customerID  = sub.CustomerID;
                        inOut       = sub.InOut;
                        invoiceCode = sub.InvoiceCode;
                    }
                    var invoice = _InvoiceRepository.GetSingleById(item.id);
                    invoice.InvoiceCode = invoiceCode;
                    invoice.InOut       = inOut;
                    invoice.Value       = totalValue;
                    invoice.CustomerID  = customerID;
                    invoice.IsActive    = true;
                    _InvoiceRepository.Update(invoice);
                }
                _unitOfWork.Commit();
                response.Message = CommonConstants.AddSuccess;
                response.Result  = result;
            }
            catch (Exception ex)
            {
                response.Code    = CommonConstants.ApiResponseExceptionCode;
                response.Message = CommonConstants.ErrorMessage + " " + ex.Message;
            }
            return(response);
        }
Пример #3
0
        public IActionResult createAllInvoic(string Invoice_NO, int StoreID, string date, double Taxes)
        {
            // var net = Taxes + total;
            InvoiceHeader newInvoiceHeader = new InvoiceHeader
            {
                Invoice_NO = Invoice_NO,
                IvoiceDate = DateTime.Parse(date),
                StoreID    = StoreID,
                Taxes      = Taxes,
                Total      = 0, // total
                Net        = 0, //total + taxes
            };

            _invoiceHeaderRepository.Add(newInvoiceHeader);

            var InvoiceHeaderID = _invoiceHeaderRepository.GetAllInvoiceHeader().LastOrDefault();

            foreach (var item in Details)
            {
                InvoiceDetail newInvoiceDetail = new InvoiceDetail
                {
                    ItemID          = item.ItemID,
                    UnitID          = item.UnitID,
                    InvoiceHeaderID = InvoiceHeaderID.ID,
                    Discount        = item.Discount,
                    Net             = item.Net,
                    Price           = item.Price,
                    quntity         = item.quntity,
                    Total           = item.Total
                };
                _invoiceDetailRepository.Add(newInvoiceDetail);
            }



            return(View("Index"));
        }
Пример #4
0
        /// <summary>
        /// Add new InvoiceDetail
        /// </summary>
        /// <param name="obj">InvoiceDetail</param>
        /// <returns></returns>
        public ApiResponseViewModel Add(InvoiceDetail obj)
        {
            var result   = new InvoiceDetail();
            var response = new ApiResponseViewModel
            {
                Code    = CommonConstants.ApiResponseSuccessCode,
                Message = null,
                Result  = null
            };

            try
            {
                result = _InvoiceDetailRepository.Add(obj);
                _unitOfWork.Commit();
                response.Message = CommonConstants.AddSuccess;
                response.Result  = result;
            }
            catch (Exception ex)
            {
                response.Code    = CommonConstants.ApiResponseExceptionCode;
                response.Message = CommonConstants.ErrorMessage + " " + ex.Message;
            }
            return(response);
        }
Пример #5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="objInvoiceDetail"></param>
 public void InsertInvoiceDetail(InvoiceDetail objInvoiceDetail)
 {
     _roleRepository.Add(objInvoiceDetail);
     _unitOfWork.Commit();
 }
Пример #6
0
        public void RepairInvoice()
        {
            DateTime start      = new DateTime(2018, 11, 1);
            DateTime serverTime = DateTime.Now;

            List <Invoice> invList = _invoiceRepository.GetMany(i => i.CreateDate >= start).ToList();

            using (var trans = _unitOfWork.BeginTransaction())
            {
                try
                {
                    foreach (Invoice inv in invList)
                    {
                        List <InvoiceDetail> invDetails = _invoiceDetailRepository.GetMany(ivd => ivd.InvoiceId == inv.Id).ToList();

                        List <SPKDetailSparepart> spkSps = _spkDetailSparepartRepository.GetMany(spkspd => spkspd.SPKId == inv.SPKId).ToList();
                        List <int> spkSpsId = spkSps.Select(x => x.Id).ToList();
                        List <SPKDetailSparepartDetail> spkSPDetails = _spkDetailSparepartDetailRepository.GetMany(spkspdt => spkSpsId.Contains(spkspdt.SPKDetailSparepartId)).ToList();

                        if (spkSPDetails.Count < spkSps.Count)
                        {
                            spkSps = spkSps.Where(spksp => !spkSPDetails.Any(spkspdt => spkspdt.SPKDetailSparepartId == spksp.Id)).ToList();

                            foreach (SPKDetailSparepart item in spkSps)
                            {
                                SpecialSparepartDetail          sspd = _specialSparepartDetailRepository.GetMany(e => e.SparepartId == item.SparepartId).FirstOrDefault();
                                List <SPKDetailSparepartDetail> newSPKdetailSparepartDetails = getRandomSPKDetails(item.SparepartId, item.TotalQuantity, sspd != null? sspd.Id : 0);

                                foreach (SPKDetailSparepartDetail spkDetailSparepartDetail in newSPKdetailSparepartDetails)
                                {
                                    SPKDetailSparepartDetail newSPKSparepartDetail = new SPKDetailSparepartDetail();

                                    newSPKSparepartDetail.CreateDate           = item.CreateDate;
                                    newSPKSparepartDetail.CreateUserId         = item.CreateUserId;
                                    newSPKSparepartDetail.ModifyDate           = serverTime;
                                    newSPKSparepartDetail.ModifyUserId         = item.ModifyUserId;
                                    newSPKSparepartDetail.Status               = (int)DbConstant.DefaultDataStatus.Active;
                                    newSPKSparepartDetail.SPKDetailSparepartId = item.Id;
                                    newSPKSparepartDetail.Qty = spkDetailSparepartDetail.Qty;

                                    if (sspd != null)
                                    {
                                        newSPKSparepartDetail.SpecialSparepartDetailId = sspd.Id;
                                        sspd.Status = (int)DbConstant.WheelDetailStatus.Installed;
                                        _specialSparepartDetailRepository.Update(sspd);
                                    }

                                    if (spkDetailSparepartDetail.PurchasingDetailId.HasValue)
                                    {
                                        newSPKSparepartDetail.PurchasingDetailId = spkDetailSparepartDetail.PurchasingDetailId;

                                        PurchasingDetail pdt = spkDetailSparepartDetail.PurchasingDetail;

                                        pdt.ModifyDate   = serverTime;
                                        pdt.ModifyUserId = item.CreateUserId;

                                        _purchasingDetailRepository.Update(pdt);
                                    }
                                    else if (spkDetailSparepartDetail.SparepartManualTransactionId.HasValue)
                                    {
                                        newSPKSparepartDetail.SparepartManualTransactionId = spkDetailSparepartDetail.SparepartManualTransactionId;

                                        SparepartManualTransaction spm = spkDetailSparepartDetail.SparepartManualTransaction;

                                        spm.ModifyDate   = serverTime;
                                        spm.ModifyUserId = item.CreateUserId;

                                        _sparepartManualTransactionRepository.Update(spm);
                                    }


                                    SPKDetailSparepartDetail insertedSPKSpDtl = _spkDetailSparepartDetailRepository.Add(newSPKSparepartDetail);

                                    InvoiceDetail invcDtl = new InvoiceDetail();

                                    invcDtl.InvoiceId = inv.Id;
                                    invcDtl.SPKDetailSparepartDetail = insertedSPKSpDtl;

                                    if (spkDetailSparepartDetail.PurchasingDetailId > 0)
                                    {
                                        invcDtl.SubTotalPrice = spkDetailSparepartDetail.PurchasingDetail.Price.AsDouble();
                                    }
                                    else
                                    {
                                        invcDtl.SubTotalPrice = spkDetailSparepartDetail.SparepartManualTransaction.Price.AsDouble();
                                    }

                                    invcDtl.Status  = (int)DbConstant.DefaultDataStatus.Active;
                                    invcDtl.FeePctg = 0;

                                    invcDtl.CreateDate   = serverTime;
                                    invcDtl.ModifyDate   = serverTime;
                                    invcDtl.ModifyUserId = item.CreateUserId;
                                    invcDtl.CreateUserId = item.CreateUserId;

                                    _invoiceDetailRepository.Add(invcDtl);

                                    _unitOfWork.SaveChanges();
                                }
                            }
                        }
                    }

                    trans.Commit();
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                    throw;
                }
            }
        }