public bool UpdateStockCardForApprovedAdjustmentVoucher(AdjustmentVoucher a)
        {
            AdjustmentVoucher av = avrepo.FindAdjustmentVoucherById(a.Id);
            List <AdjustmentVoucherDetail> avd = av.AdjustmentVoucherDetails;
            DateTime       dateTime            = DateTime.UtcNow.Date;
            DateTimeOffset dt        = new DateTimeOffset(dateTime, TimeSpan.Zero).ToUniversalTime();
            long           dateofadj = dt.ToUnixTimeMilliseconds();

            foreach (AdjustmentVoucherDetail i in avd)
            {
                Transaction t_new = new Transaction();
                t_new.ProductId = i.ProductId;
                t_new.Date      = dateofadj;
                StringBuilder builder = new StringBuilder();
                t_new.Description = builder.Append("Approved Adjustment Voucher due to ").Append(i.Reason).ToString();
                t_new.Qty         = i.QtyAdjusted;
                Transaction t_old = trepo.GetLatestTransactionByProductId(i.ProductId);
                t_new.Balance = t_old.Balance + t_new.Qty;
                if (t_new.Balance <= 0)
                {
                    t_new.Balance = 0;
                }
                t_new.UpdatedByEmpId = av.InitiatedClerkId;
                t_new.RefCode        = "AV ID: " + av.Id.ToString();
                trepo.SaveNewTransaction(t_new);
            }
            return(true);
        }
Exemple #2
0
        public List <Transaction> GetLatestTransaction(List <Product> pdt)
        {
            List <Transaction> tlist = new List <Transaction>();

            foreach (Product p in pdt)
            {
                Transaction t = trepo.GetLatestTransactionByProductId(p.Id);
                if (t == null)
                {
                    t             = new Transaction();
                    t.ProductId   = p.Id;
                    t.Balance     = 0;
                    t.Description = "No record of transaction in stock card for " + p.Id;
                }
                tlist.Add(t);
            }
            return(tlist);
        }