Ejemplo n.º 1
0
        public PurchaseOrderStatusViewModel ToViewModel(TblPurchaseOrder Model, List <TblLookup> Status)
        {
            PurchaseOrderStatusViewModel ToReturn = new PurchaseOrderStatusViewModel();

            ToReturn.ApplicationUserId = Model.ApplicationUser.Id.ToString();
            ToReturn.Id = Model.ID.ToString();

            foreach (var S in Status)
            {
                ToReturn.NewStatus.Add(S.Value);
            }

            ToReturn.Budget          = Model.Budget;
            ToReturn.Code            = Model.Code;
            ToReturn.DateFullfilled  = Model.DateFullfilled;
            ToReturn.DateRaised      = Model.DateRaised;
            ToReturn.DateRequired    = Model.DateRequired;
            ToReturn.InvoiceToDetail = Model.InvoiceToDetail;
            ToReturn.Note            = Model.Note;
            ToReturn.Price           = Model.Price;
            ToReturn.Status          = Model.Status;
            ToReturn.Tax             = Model.Tax;
            ToReturn.Total           = Model.Total;
            return(ToReturn);
        }
Ejemplo n.º 2
0
        public void ClearForm()
        {
            btnAdd.Show();
            btnSave.Hide();

            //load combobox
            lstPurchaseOrder = _purchaseOrderService.GetPurchaseOrders();
            TblPurchaseOrder item = new TblPurchaseOrder();

            item.PurchaseOrderCode = "---Select PO--";
            item.PurchaseOrderId   = 0;

            lstPurchaseOrder.Add(item);
            cmbPurchaseOrder.DataSource = lstPurchaseOrder;


            cmbPurchaseOrder.ValueMember        = "PurchaseOrderId";
            cmbPurchaseOrder.DisplayMember      = "PurchaseOrderCode";
            cmbPurchaseOrder.DropDownStyle      = System.Windows.Forms.ComboBoxStyle.DropDown;
            cmbPurchaseOrder.AutoCompleteMode   = AutoCompleteMode.SuggestAppend;
            cmbPurchaseOrder.AutoCompleteSource = AutoCompleteSource.ListItems;
            cmbPurchaseOrder.SelectedValue      = 0;
            //till here
            BindOtherPurchases(0);
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Edit(Guid id, [Bind("Code,Status,Budget,DateRaised,DateFullfilled,DateRequired,Note,To,DeliverTo,InvoiceTo,Price,Tax,Total,ApplicationUserId,ID,RowVersionNo")] TblPurchaseOrder tblPurchaseOrder)
        {
            if (id != tblPurchaseOrder.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(tblPurchaseOrder);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TblPurchaseOrderExists(tblPurchaseOrder.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ApplicationUserId"] = new SelectList(_context.Users, "Id", "Id", tblPurchaseOrder.ApplicationUserId);
            return(View(tblPurchaseOrder));
        }
Ejemplo n.º 4
0
        public TblPurchaseOrder GetPurchaseOrderById(int poID)
        {
            TblPurchaseOrder purchaseOrder = (from p in dbContext.TblPurchaseOrder
                                              where p.IsDeleted == false && p.PurchaseOrderId == poID
                                              select p).FirstOrDefault();

            return(purchaseOrder);
        }
Ejemplo n.º 5
0
        public PurchaseOrderViewModel ToViewModel(TblPurchaseOrder Model, ApplicationUser AU)
        {
            PurchaseOrderViewModel ToReturn = new PurchaseOrderViewModel();

            if (Model.ApplicationUser == null && Model.ApplicationUserId != null)
            {
                ToReturn.ApplicationUserId = Model.ApplicationUserId.ToString();
            }
            else
            {
                ToReturn.ApplicationUserId = Model.ApplicationUser.Id.ToString();
            }

            ToReturn.FromDetail = AU.PersonName + "<BR />" + AU.Email + "<BR />" + AU.Organisation;


            ToReturn.Budget          = Model.Budget;
            ToReturn.Code            = Model.Code;
            ToReturn.DateFullfilled  = Model.DateFullfilled;
            ToReturn.DateRaised      = Model.DateRaised;
            ToReturn.DateRequired    = Model.DateRequired;
            ToReturn.DeliverTo       = Model.DeliverTo;
            ToReturn.DeliverToDetail = Model.DeliverToDetail;
            ToReturn.Id              = Model.ID.ToString();
            ToReturn.InvoiceTo       = Model.InvoiceTo;
            ToReturn.InvoiceToDetail = Model.InvoiceToDetail;
            ToReturn.Note            = Model.Note;
            ToReturn.Price           = Model.Price;
            ToReturn.RowVersionNo    = Model.RowVersionNo;
            ToReturn.Status          = Model.Status;
            ToReturn.Tax             = Model.Tax;
            ToReturn.To              = Model.To;
            ToReturn.ToDetail        = Model.ToDetail;
            ToReturn.Total           = Model.Total;
            if (Model.Items != null)
            {
                foreach (var I in Model.Items)
                {
                    ToReturn.Items.Add(new PurchaseOrderItemViewModel()
                    {
                        Brand       = I.Brand,
                        Code        = I.Code,
                        Description = I.Description,
                        Id          = I.ID.ToString(),
                        Name        = I.Name,
                        Price       = I.Price,
                        Quantity    = I.Quantity,
                        RowVersion  = I.RowVersionNo,
                        Tax         = I.Tax,
                        TaxCode     = I.TaxCode,
                        Total       = I.Total
                    });
                }
            }
            return(ToReturn);
        }
        public async Task <IActionResult> SubmitPurchaseOrderForm([FromBody] PurchaseOrderFormModel model)
        {
            var userId = GetUserId();

            if (ModelState.IsValid)
            {
                var newPurchaseOrder = new TblPurchaseOrder
                {
                    SupplierId  = model.SupplierID,
                    IssuedDate  = model.IssuedDate,
                    QuoteRef    = model.QuoteRef,
                    Potype      = model.POType,
                    Poamount    = model.Poamount,
                    QuoMasterId = model.QuoMasterId,
                    CreatedDate = DateTime.Now
                };

                await _purchaseOrderRepository.CreateAsync(newPurchaseOrder);

                var endPointId = await GetEndPointId();

                var tblStaff = await _staffRepository.FirstOrDefaultAsync(x => x.AspnetUserId == userId);

                var newAudit = new TblAuthList
                {
                    Title       = "ContractAward",
                    Url         = "/api/v1/contractaward/submitpurchaseorderform",
                    CreatedDate = DateTime.Now,
                    Status      = 0,
                    StaffId     = tblStaff.StaffId,
                    BatchId     = Guid.NewGuid().ToString()
                };

                await _auditRepository.CreateAsync(newAudit);

                var emailAddress = await _emailAddressRepository.SendEmailAddress(endPointId, 1);

                await _auditRepository.SaveChangesAsync();

                return(Ok(
                           new
                {
                    message = "Purchase order created successfully",
                    EmailAddress = emailAddress
                }));
            }

            return(BadRequest(new
            {
                Errors = new[] { "Please input correct values" }
            }));
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> Create([Bind("Code,Status,Budget,DateRaised,DateFullfilled,DateRequired,Note,To,DeliverTo,InvoiceTo,Price,Tax,Total,ApplicationUserId,ID,RowVersionNo")] TblPurchaseOrder tblPurchaseOrder)
        {
            if (ModelState.IsValid)
            {
                tblPurchaseOrder.ID = Guid.NewGuid();
                _context.Add(tblPurchaseOrder);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ApplicationUserId"] = new SelectList(_context.Users, "Id", "Id", tblPurchaseOrder.ApplicationUserId);
            return(View(tblPurchaseOrder));
        }
Ejemplo n.º 8
0
        // takes view model and returns the table model
        public TblPurchaseOrder ToTableModel(PurchaseOrderViewModel Model)
        {
            TblPurchaseOrder ToReturn = new TblPurchaseOrder();

            ToReturn.ApplicationUser.Id = Guid.Parse(Model.ApplicationUserId);
            ToReturn.Budget             = Model.Budget;
            ToReturn.Code           = Model.Code;
            ToReturn.DateFullfilled = Model.DateFullfilled;
            ToReturn.DateRaised     = Model.DateRaised;
            ToReturn.DateRequired   = Model.DateRequired;
            ToReturn.DeliverTo      = Model.DeliverTo;
            ToReturn.ID             = Guid.Parse(Model.Id);
            ToReturn.InvoiceTo      = Model.InvoiceTo;
            ToReturn.Note           = Model.Note;
            ToReturn.Price          = Model.Price;
            ToReturn.RowVersionNo   = Model.RowVersionNo;
            ToReturn.Status         = Model.Status;
            ToReturn.Tax            = Model.Tax;
            ToReturn.To             = Model.To;
            ToReturn.Total          = Model.Total;
            if (Model.Items.Count > 0)
            {
                foreach (var I in Model.Items)
                {
                    ToReturn.Items.Add(new TblPurchaseOrderItem()
                    {
                        Brand        = I.Brand,
                        Code         = I.Code,
                        Description  = I.Description,
                        ID           = Guid.Parse(I.Description),
                        Name         = I.Name,
                        Price        = I.Price,
                        Quantity     = I.Quantity,
                        RowVersionNo = I.RowVersion,
                        Tax          = I.Tax,
                        TaxCode      = I.TaxCode,
                        Total        = I.Total
                    });
                }
            }
            return(ToReturn);
        }
Ejemplo n.º 9
0
        public BuyEVoucherResponse BuyEVoucher(BuyEVoucherRequest _request)
        {
            BuyEVoucherResponse response = new BuyEVoucherResponse();
            string validateMsg           = "";

            validateMsg = ValidateBuyEVoucher(_request);
            if (string.IsNullOrEmpty(validateMsg))
            {
                using (var dbContextTransaction = db_Evoucher.Database.BeginTransaction())
                {
                    //Thread.Sleep(60000);

                    try
                    {
                        var tblEvoucher = (from v in db_Evoucher.TblEvouchers
                                           where v.VoucherNo == _request.VoucherNo
                                           select v
                                           ).FirstOrDefault();
                        if (tblEvoucher == null)
                        {
                            validateMsg = "No Voucher Found";
                        }
                        else
                        {
                            if (tblEvoucher.ExpiryDate < DateTime.Now && tblEvoucher.Status != (int)RecordStatus.Active)
                            {
                                validateMsg = $"{validateMsg}\r\nVoucher has been expired or out of stock.";
                            }
                            else if (tblEvoucher.Quantity <= 0)
                            {
                                validateMsg = $"{validateMsg}\r\nOut of stock.";
                            }
                            else if (tblEvoucher.Quantity < _request.Quantity)
                            {
                                validateMsg = $"{validateMsg}\r\nOrder quantity exceed the avaliable stock.";
                            }
                            else
                            {
                                var previousOrderList = (from p in db_Evoucher.TblPurchaseOrders
                                                         where p.VoucherNo == _request.VoucherNo &&
                                                         p.BuyerPhone == _request.BuyerPhone
                                                         select new
                                {
                                    p.BuyType,
                                    p.Quantity
                                }
                                                         ).ToList();

                                if (previousOrderList == null || previousOrderList.Count <= 0)
                                {
                                    if (_request.BuyType == Constant.EVOUCHER_BUY_TYPE_ONLYME &&
                                        _request.Quantity > tblEvoucher.MaxLimit
                                        )
                                    {
                                        validateMsg = $"{validateMsg}\r\nReach Limitted Quantity,You can't buy anymore.";
                                    }
                                    else if (_request.Quantity > tblEvoucher.GiftPerUserLimit)
                                    {
                                        validateMsg = $"{validateMsg}\r\nReach Limitted Gift Quantity,You can't buy anymore.";
                                    }
                                }
                                else
                                {
                                    var buyGroup = previousOrderList.GroupBy(x => x.BuyType)
                                                   .Select(x => new
                                    {
                                        BuyType  = x.First().BuyType,
                                        Quantity = x.Sum(x => x.Quantity)
                                    }).ToList();
                                    var OwnUsageQuantity  = buyGroup.Where(x => x.BuyType == Constant.EVOUCHER_BUY_TYPE_ONLYME).Select(x => x.Quantity).FirstOrDefault();
                                    var GiftUsageQuantity = buyGroup.Where(x => x.BuyType == Constant.EVOUCHER_BUY_TYPE_GIFT).Select(x => x.Quantity).FirstOrDefault();
                                    var totalUsage        = OwnUsageQuantity + GiftUsageQuantity;

                                    if (_request.Quantity + totalUsage > tblEvoucher.MaxLimit)
                                    {
                                        if (totalUsage > tblEvoucher.MaxLimit)
                                        {
                                            validateMsg = $"{validateMsg}\r\nReach Limitted Quantity,You can buy anymore.";
                                        }
                                        else
                                        {
                                            validateMsg = $"{validateMsg}\r\nReach Limitted Quantity,You can buy only {tblEvoucher.MaxLimit - totalUsage} voucher.";
                                        }
                                    }
                                    else if (_request.BuyType == Constant.EVOUCHER_BUY_TYPE_ONLYME &&
                                             _request.Quantity + OwnUsageQuantity > tblEvoucher.MaxLimit
                                             )
                                    {
                                        if (OwnUsageQuantity > tblEvoucher.MaxLimit)
                                        {
                                            validateMsg = $"{validateMsg}\r\nOwn Usage Reach Limitted Quantity,You can't buy anymore.";
                                        }
                                        else
                                        {
                                            validateMsg = $"{validateMsg}\r\nOwn Usage Reach Limitted Quantity,You can buy only {tblEvoucher.MaxLimit - OwnUsageQuantity} voucher.";
                                        }
                                    }
                                    else if (_request.Quantity + GiftUsageQuantity > tblEvoucher.GiftPerUserLimit)
                                    {
                                        if (GiftUsageQuantity > tblEvoucher.GiftPerUserLimit)
                                        {
                                            validateMsg = $"{validateMsg}\r\nGift Usage Reach Limitted Quantity,You can't buy anymore.";
                                        }
                                        else
                                        {
                                            validateMsg = $"{validateMsg}\r\nGift Usage Reach Limitted Quantity,You can buy only {tblEvoucher.MaxLimit - GiftUsageQuantity} voucher.";
                                        }
                                    }
                                }

                                if (validateMsg == "")
                                {
                                    var UpdatetblEvoucher = (from v in db_Evoucher.TblEvouchers
                                                             where v.VoucherNo == _request.VoucherNo
                                                             select v
                                                             ).FirstOrDefault();
                                    UpdatetblEvoucher.Quantity = UpdatetblEvoucher.Quantity - _request.Quantity;
                                    decimal totalPrice = UpdatetblEvoucher.SellingPrice;
                                    short   sellingDiscount;
                                    if (_request.PaymentMethod == UpdatetblEvoucher.PaymentMethod &&
                                        UpdatetblEvoucher.SellingDiscount != null)
                                    {
                                        var discountAmount = totalPrice * (decimal)((UpdatetblEvoucher.SellingDiscount ?? 0) / 100.0);
                                        totalPrice = totalPrice - discountAmount;
                                        if (totalPrice < 0)
                                        {
                                            totalPrice = 0;
                                        }
                                        sellingDiscount = UpdatetblEvoucher.SellingDiscount ?? 0;
                                    }
                                    else
                                    {
                                        sellingDiscount = 0;
                                    }

                                    var pOrderList = (from v in db_Evoucher.TblPurchaseOrders
                                                      select new
                                    {
                                        v.Id
                                    }
                                                      ).ToList();

                                    int maxNo = 1;
                                    if (pOrderList != null && pOrderList.Count > 0)
                                    {
                                        maxNo = pOrderList.Max(x => x.Id);
                                        maxNo++;
                                    }

                                    TblPurchaseOrder order = new TblPurchaseOrder
                                    {
                                        PurchaseOrderNo    = "PO-" + maxNo.ToString().PadLeft(6, '0'),
                                        BuyerName          = _request.BuyerName,
                                        BuyerPhone         = _request.BuyerPhone,
                                        BuyType            = _request.BuyType,
                                        OrderDate          = DateTime.Now,
                                        PaymentMethod      = _request.PaymentMethod,
                                        SellingDiscount    = sellingDiscount,
                                        Quantity           = _request.Quantity,
                                        Status             = (int)RecordStatus.Active,
                                        TotalSellingAmount = totalPrice,
                                        SellingPrice       = UpdatetblEvoucher.SellingPrice,
                                        ExpiryDate         = UpdatetblEvoucher.ExpiryDate,
                                        ImagePath          = UpdatetblEvoucher.ImagePath,
                                        VoncherAmount      = UpdatetblEvoucher.VoucherAmount,
                                        VoucherNo          = UpdatetblEvoucher.VoucherNo,
                                        VoucherGenerated   = false,
                                    };

                                    db_Evoucher.TblPurchaseOrders.Add(order);
                                    db_Evoucher.SaveChanges();

                                    dbContextTransaction.Commit();
                                    response.OrderNo           = order.PurchaseOrderNo;
                                    response.IsPurchaseSuccess = true;
                                }
                            }
                        }
                    }catch (Exception e)
                    {
                        response.StatusCode   = 500;
                        response.ErrorType    = "validation-error";
                        response.ErrorMessage = e.Message;

                        dbContextTransaction.Rollback();
                    }
                }
            }
            else
            {
                response.StatusCode   = 400;
                response.ErrorType    = "validation-error";
                response.ErrorMessage = validateMsg;
            }
            if (validateMsg != "")
            {
                response.StatusCode   = 400;
                response.ErrorType    = "validation-error";
                response.ErrorMessage = validateMsg;
            }

            return(response);
        }
Ejemplo n.º 10
0
        public PurchaseOrderViewModel ToViewModel(TblPurchaseOrder Model, List <string> BudgetCodes, List <OrgDetail> Organisations, TblOrganisation OrgItems)
        {
            PurchaseOrderViewModel ToReturn = new PurchaseOrderViewModel();

            ToReturn.ApplicationUserId = Model.ApplicationUser.Id.ToString();
            ToReturn.Budget            = Model.Budget;
            ToReturn.BudgetCodes       = BudgetCodes;
            ToReturn.Code             = Model.Code;
            ToReturn.DateFullfilled   = Model.DateFullfilled;
            ToReturn.DateRaised       = Model.DateRaised;
            ToReturn.DateRequired     = Model.DateRequired;
            ToReturn.DeliverTo        = Model.DeliverTo;
            ToReturn.DeliverToDetail  = Model.DeliverToDetail;
            ToReturn.DeliverToOptions = Organisations;
            ToReturn.Id               = Model.ID.ToString();
            ToReturn.InvoiceTo        = Model.InvoiceTo;
            ToReturn.InvoiceToDetail  = Model.InvoiceToDetail;
            ToReturn.InvoiceToOptions = Organisations;
            ToReturn.Note             = Model.Note;
            ToReturn.Price            = Model.Price;
            ToReturn.RowVersionNo     = Model.RowVersionNo;
            ToReturn.Status           = Model.Status;
            ToReturn.Tax              = Model.Tax;
            ToReturn.To               = Model.To;
            ToReturn.ToDetail         = Model.ToDetail;
            ToReturn.ToOptions        = Organisations;
            ToReturn.Total            = Model.Total;
            ToReturn.HTMLSelectOrganisationItems.Add(new SelectOrgItem()
            {
                Text     = "Select Item",
                Value    = "SelectItem",
                Selected = true
            });
            ToReturn.HTMLSelectOrganisationItems.Add(new SelectOrgItem()
            {
                Text     = "New Item",
                Value    = "NewItem",
                Selected = true
            });

            if (OrgItems != null)
            {
                foreach (var I in OrgItems.Items)
                {
                    ToReturn.HTMLSelectOrganisationItems.Add(new SelectOrgItem()
                    {
                        Text     = I.Code,
                        Value    = I.ID.ToString(),
                        Selected = false
                    });
                }
            }



            //if (OrgItems != null)
            //{
            //    foreach (var I in OrgItems.Items)
            //    {
            //        ToReturn.HTMLSelectOrganisationItems.Add(new SelectOrgItem()
            //        {
            //             Text = I.Name,
            //             Value = I.ID.ToString()
            //        });
            //    }
            //}
            if (Model.Items != null)
            {
                foreach (var I in Model.Items)
                {
                    ToReturn.Items.Add(new PurchaseOrderItemViewModel()
                    {
                        Brand       = I.Brand,
                        Code        = I.Code,
                        Description = I.Description,
                        Id          = I.ID.ToString(),
                        Name        = I.Name,
                        Price       = I.Price,
                        Quantity    = I.Quantity,
                        RowVersion  = I.RowVersionNo,
                        Tax         = I.Tax,
                        TaxCode     = I.TaxCode,
                        Total       = I.Total
                    });
                }
            }
            return(ToReturn);
        }
Ejemplo n.º 11
0
        public TblPurchaseOrder UpdatePO(TblPurchaseOrder PO, PurchaseOrderJsonModel FromView)
        {
            PO.Budget          = FromView.BudgetCode;
            PO.DateRaised      = FromView.DateRaised;
            PO.DateRequired    = FromView.DateRequiredBy;
            PO.DeliverTo       = FromView.DeliverTo;
            PO.InvoiceTo       = FromView.InvoiceTo;
            PO.To              = FromView.To;
            PO.ToDetail        = FromView.ToDetail;
            PO.DeliverTo       = FromView.DeliverTo;
            PO.DeliverToDetail = FromView.DeliverToDetail;
            PO.InvoiceTo       = FromView.InvoiceTo;
            PO.InvoiceToDetail = FromView.InvoiceToDetail;
            PO.Note            = FromView.Note;
            PO.Price           = FromView.Price;
            PO.Tax             = FromView.Tax;
            PO.Total           = FromView.Total;

            // remove items from PO if they have been removed from View


            List <TblPurchaseOrderItem> Toremove = new List <TblPurchaseOrderItem>();

            foreach (TblPurchaseOrderItem I in PO.Items)
            {
                var result = FromView.LineItem.Find(x => x.DBLineId == I.ID.ToString());
                if (result == null)
                {
                    Toremove.Add(I);
                }
            }

            foreach (var I in Toremove)
            {
                PO.Items.Remove(I);
            }



            if (PO.Items == null)
            {
                PO.Items = new List <TblPurchaseOrderItem>();
                foreach (var L in FromView.LineItem)
                {
                    PO.Items.Add(new TblPurchaseOrderItem()
                    {
                        Brand       = L.brand,
                        Code        = L.code,
                        Description = L.description,
                        Name        = L.name,
                        Price       = L.price,
                        Quantity    = L.quantity,
                        Tax         = L.tax,
                        TaxCode     = L.taxcode,
                        Total       = L.total
                    });
                }
            }
            else
            {
                // now remove Items from the
                foreach (var L in FromView.LineItem)
                {
                    TblPurchaseOrderItem result = new TblPurchaseOrderItem();
                    try
                    {
                        var Lineid = Guid.Parse(L.DBLineId);
                        result = PO.Items.Where(x => x.ID == Guid.Parse(L.DBLineId)).Single();
                    }
                    catch
                    {
                        result = null;
                    }


                    if (result != null)
                    {
                        result.Brand       = L.brand;
                        result.Code        = L.code;
                        result.Description = L.description;
                        result.Name        = L.name;
                        result.Price       = L.price;
                        result.Quantity    = L.quantity;
                        result.Tax         = L.tax;
                        result.TaxCode     = L.taxcode;
                        result.Total       = L.total;
                    }
                    else
                    {
                        PO.Items.Add(new TblPurchaseOrderItem()
                        {
                            Brand       = L.brand,
                            Code        = L.code,
                            Description = L.description,
                            Name        = L.name,
                            Price       = L.price,
                            Quantity    = L.quantity,
                            Tax         = L.tax,
                            TaxCode     = L.taxcode,
                            Total       = L.total
                        });
                    };
                }
            }
            return(PO);
        }