Esempio n. 1
0
        public ActionResult Detail(ListPurchaseOrderViewModel model)
        {
            if (ModelState.IsValid)
            {
                using (POSContext context = new POSContext())
                {
                    using (var dbTransacyion = context.Database.BeginTransaction())
                    {
                        int           UserId = User.Identity.GetUserId <int>();
                        PurchaseOrder item   = context.TPurchaseOrder.Where(m => m.ID == model.ID).FirstOrDefault();
                        item.StatusID   = model.StatusID;
                        item.ModifiedBy = UserId;
                        item.ModifiedOn = DateTime.Now;
                        context.SaveChanges();

                        PurchaseOrderHistory item2 = new PurchaseOrderHistory()
                        {
                            HeaderID   = item.ID,
                            StatusID   = model.StatusID,
                            CreatedBy  = UserId,
                            ModifiedBy = UserId,
                            CreatedOn  = DateTime.Now,
                            ModifiedOn = DateTime.Now
                        };
                        context.TPurchaseOrderHistory.Add(item2);
                        context.SaveChanges();

                        if (model.StatusID == 2)
                        {
                            int i = 0;
                            foreach (var data in model.VariantID)
                            {
                                int           variantid = data;
                                ItemsIventory item3     = context.TItemsIventory.Where(m => m.VariantID == variantid).FirstOrDefault();
                                item3.PurchaseOrder = model.Quantity[i];
                                i++;
                            }
                            context.SaveChanges();
                        }

                        try
                        {
                            dbTransacyion.Commit();
                            return(RedirectToAction("Index"));
                        }
                        catch (Exception)
                        {
                            throw;
                        }
                    }
                }
            }
            return(PartialView("Detail", model));
        }
Esempio n. 2
0
        /// <summary>
        /// Tracking purchaseOrderHistory
        /// </summary>
        /// <param name="cancellationToken"></param>
        /// <param name="accountingItemLog"></param>
        /// <returns></returns>
        private async Task CreatePurchaseOrderHistory(CancellationToken cancellationToken, AuditEntry accountingItemLog)
        {
            try
            {
                var poNewHistory = new PurchaseOrderHistoryUnit();
                var poOldHistory = new PurchaseOrderHistoryUnit();

                var PropertiesList       = accountingItemLog.Properties.FindAll(u => u.PropertyName != "LajitId" && u.PropertyName != "Id");
                var propAccountingItemId = accountingItemLog.Properties.Find(u => u.PropertyName == "Id");
                var isClose = accountingItemLog.Properties.Find(u => u.PropertyName == "IsClose");

                if (accountingItemLog.StateName == AuditEntryState.EntityAdded.ToString())
                {
                    poNewHistory = GetPoNewValues(PropertiesList);
                    poNewHistory.AccountingItemId   = Convert.ToInt64(propAccountingItemId.NewValue);
                    poNewHistory.ModificationTypeId = ModificationType.Created;
                    PurchaseOrderHistory.Add(poNewHistory);
                    await base.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
                }
                else if (accountingItemLog.StateName == AuditEntryState.EntityModified.ToString())
                {
                    poNewHistory = GetPoNewValues(PropertiesList);
                    poOldHistory = GetPoOldValues(PropertiesList);

                    poNewHistory.AccountingItemId = Convert.ToInt64(propAccountingItemId.NewValue);
                    poOldHistory.AccountingItemId = Convert.ToInt64(propAccountingItemId.OldValue);



                    //If Job OR Line Changed
                    if (poOldHistory.JobId != poNewHistory.JobId || poOldHistory.AccountId != poNewHistory.AccountId)
                    {
                        poOldHistory.Amount             = -poOldHistory.Amount;
                        poOldHistory.ModificationTypeId = ModificationType.Linechange;
                        if (poNewHistory.SourceTypeId != SourceType.PO)
                        {
                            poOldHistory.SourceTypeId = poNewHistory.SourceTypeId;
                        }

                        PurchaseOrderHistory.Add(poOldHistory);
                        await base.SaveChangesAsync(cancellationToken).ConfigureAwait(false);

                        poOldHistory.Amount = Math.Abs(poOldHistory.Amount.Value);

                        poNewHistory.Amount             = Math.Abs(poOldHistory.Amount.Value);
                        poNewHistory.ModificationTypeId = ModificationType.Linechange;
                        PurchaseOrderHistory.Add(poNewHistory);
                        await base.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
                    }

                    //if amount Changed
                    poNewHistory = GetPoNewValues(PropertiesList);
                    int value = decimal.Compare(poNewHistory.Amount.Value, poOldHistory.Amount.Value);
                    if (value != 0)
                    {
                        poNewHistory.AccountingItemId   = Convert.ToInt64(propAccountingItemId.NewValue);
                        poNewHistory.ChangeInAmount     = poNewHistory.Amount.Value - poOldHistory.Amount.Value;
                        poNewHistory.ModificationTypeId = poNewHistory.SourceTypeId == SourceType.PO ? (value > 0 ? ModificationType.IncreasedAmount : ModificationType.DecreasedAmount) : ModificationType.Reduced;
                        PurchaseOrderHistory.Add(poNewHistory);
                        await base.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
                    }

                    //if PO is Closed
                    if (isClose.NewValue.ToString().Length > 0 && Convert.ToBoolean(isClose.NewValue))
                    {
                        poNewHistory = GetPoNewValues(PropertiesList);
                        poNewHistory.AccountingItemId   = Convert.ToInt64(propAccountingItemId.NewValue);
                        poNewHistory.ModificationTypeId = ModificationType.Closed;
                        PurchaseOrderHistory.Add(poNewHistory);
                        await base.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
                    }
                }
                else if (accountingItemLog.StateName == AuditEntryState.EntityDeleted.ToString())
                {
                    poOldHistory = GetPoOldValues(PropertiesList);
                    poOldHistory.ModificationTypeId = ModificationType.Deleted;
                    poOldHistory.AccountingItemId   = Convert.ToInt64(propAccountingItemId.OldValue);
                    PurchaseOrderHistory.Add(poOldHistory);
                    await base.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 3
0
        public ActionResult Add(PurchaseOrderViewModel model)
        {
            if (ModelState.IsValid)
            {
                using (POSContext context = new POSContext())
                {
                    using (var dbTransaction = context.Database.BeginTransaction())
                    {
                        int           UserId  = User.Identity.GetUserId <int>();
                        string        OrderNo = PurchaseOrderDAL.OrderNo();
                        PurchaseOrder order   = new PurchaseOrder()
                        {
                            OutletID   = model.OutletID,
                            OrderNo    = OrderNo,
                            StatusID   = 1,
                            SupplierID = model.SupplierID,
                            Notes      = model.Notes,
                            Total      = model.Total,
                            CreatedBy  = UserId,
                            CreatedOn  = DateTime.Now,
                            ModifiedBy = UserId,
                            ModifiedOn = DateTime.Now
                        };
                        context.TPurchaseOrder.Add(order);
                        context.SaveChanges();


                        PurchaseOrderHistory orderhis = new PurchaseOrderHistory()
                        {
                            HeaderID   = order.ID,
                            StatusID   = 1,
                            CreatedBy  = UserId,
                            CreatedOn  = DateTime.Now,
                            ModifiedBy = UserId,
                            ModifiedOn = DateTime.Now
                        };
                        context.TPurchaseOrderHistory.Add(orderhis);
                        context.SaveChanges();
                        foreach (var item in model.VariantID)
                        {
                            PurchaseOrderDetail orderdetail = new PurchaseOrderDetail()
                            {
                                HeaderID   = order.ID,
                                Quantity   = model.Quantity,
                                SubTotal   = model.SubTotal,
                                VariantID  = item,
                                UnitCost   = model.UnitCost,
                                CreatedBy  = UserId,
                                CreatedOn  = DateTime.Now,
                                ModifiedBy = UserId,
                                ModifiedOn = DateTime.Now
                            };
                            context.TPurchaseOrderDetail.Add(orderdetail);
                        }
                        context.SaveChanges();


                        try
                        {
                            dbTransaction.Commit();
                            return(RedirectToAction("Index"));
                        }
                        catch (Exception)
                        {
                            dbTransaction.Rollback();
                        }
                    }
                }
            }
            return(PartialView("Add", model));
        }