Ejemplo n.º 1
0
        public async Task <IActionResult> Create([Bind("Id,Code,Bar_Code,Name,Parent_Code,Type,Unit,Rate,Is_Vatable,Remarks")] Item item)
        {
            if (ModelState.IsValid)
            {
                _context.Add(item);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(item));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("Id,Code,Description")] ItemType itemType)
        {
            if (ModelState.IsValid)
            {
                _context.Add(itemType);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(itemType));
        }
        public async Task <IActionResult> Create([Bind("Id,Initial,Name,Is_Active,Remarks,Cash_Drop_Limit")] Terminal terminal)
        {
            if (ModelState.IsValid)
            {
                _context.Add(terminal);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(terminal));
        }
        public async Task <IActionResult> Create([Bind("Id,Code,Parent_Code,Description,Indentation,Order,Has_Child,Modified_Date")] ItemCategory itemCategory)
        {
            if (ModelState.IsValid)
            {
                itemCategory.Id           = Guid.NewGuid().ToString();
                itemCategory.ModifiedDate = DateTime.Now;
                _context.Add(itemCategory);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(itemCategory));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Create(Denomination denomination)
        {
            if (ModelState.IsValid)
            {
                if (denomination.Date.ToShortDateString() != System.DateTime.Now.ToShortDateString())
                {
                    return(StatusCode(400, "Date not Up-to-Date !!"));
                }
                //check if Session present
                denomination.User_Id = User.Identity.Name;
                IList <Settlement> settlementData = _context.Settlement.Where(x => x.UserId == denomination.User_Id).ToList();
                if (settlementData == null || settlementData.Count == 0)
                {
                    ModelState.AddModelError(string.Empty, "Sorry, No Transaction Found In Your Name !!");
                }
                else if (!settlementData.Any(x => x.Status == "Open"))
                {
                    if (settlementData.Any(x => x.Status == "Closed"))
                    {
                        ModelState.AddModelError(string.Empty, "Already Saved, Cannot Save Twice !!");
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, "Sorry, No Transaction Found In Your Name !!");
                    }
                }
                else
                {
                    denomination.TotalCash = denomination.Total;//CalcTotalCash(denomination);
                    _context.Add(denomination);

                    await _context.SaveChangesAsync();

                    var newSettlementData = settlementData.Where(x => x.Status == "Open");
                    foreach (var item in newSettlementData)
                    {
                        item.Status                = "Closed";
                        item.DenominationId        = denomination.Id;
                        _context.Entry(item).State = EntityState.Modified;
                    }
                    await _context.SaveChangesAsync();

                    TempData["StatusMessage"] = "Saved Successfully";
                    return(RedirectToAction(nameof(Edit), new { id = denomination.Id }));
                }
            }
            ViewData["Terminal_Id"] = new SelectList(_context.Terminal, "Id", "Name", denomination.Terminal_Id);

            return(View(denomination));
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Index([FromBody] CreditNote creditNote)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    Store store = JsonConvert.DeserializeObject <Store>(HttpContext.Session.GetString("Store"));;
                    creditNote.Id                 = Guid.NewGuid();
                    creditNote.Credit_Note_Id     = _context.CreditNote.Select(x => x.Credit_Note_Id).DefaultIfEmpty(0).Max() + 1;
                    creditNote.Credit_Note_Number = "CN-" + creditNote.Credit_Note_Id.ToString("0000") + "-" + store.INITIAL + '-' + store.FISCAL_YEAR;
                    creditNote.Trans_Time         = DateTime.Now.TimeOfDay;
                    creditNote.Division           = "Divisioin";
                    creditNote.Terminal           = HttpContext.Session.GetString("Terminal");
                    creditNote.Created_Date       = DateTime.Now;
                    creditNote.Created_By         = User.Identity.Name;
                    creditNote.isRedeem           = creditNote.isRedeem;

                    if (creditNote.isRedeem == true)
                    {
                        creditNote.Remarks = "Claimed";
                    }
                    _context.Add(creditNote);

                    foreach (var item in creditNote.CreditNoteItems)
                    {
                        item.Credit_Note_Id     = creditNote.Id;
                        item.Credit_Note_Number = creditNote.Credit_Note_Number;
                        _context.CreditNoteItem.Add(item);
                    }

                    //save to print table
                    InvoicePrint print = new InvoicePrint()
                    {
                        InvoiceNumber    = creditNote.Credit_Note_Number,
                        Type             = "CreditNote",
                        FirstPrintedDate = DateTime.Now,
                        FirstPrintedBy   = User.Identity.Name,
                        PrintCount       = 1
                    };
                    _context.InvoicePrint.Add(print);

                    await _context.SaveChangesAsync();

                    //now update invoice remarks also
                    SalesInvoice invoice = _context.SalesInvoice.FirstOrDefault(x => x.Invoice_Number == creditNote.Reference_Number.Trim());
                    invoice.Remarks = "Return";
                    _context.Entry(invoice).State = EntityState.Modified;
                    InvoiceMaterializedView invoiceMaterializedViewOld = _context.InvoiceMaterializedView.FirstOrDefault(x => x.BillNo == creditNote.Reference_Number.Trim());
                    invoiceMaterializedViewOld.IsBillActive          = false;
                    _context.Entry(invoiceMaterializedViewOld).State = EntityState.Modified;


                    InvoiceMaterializedView view = new InvoiceMaterializedView()
                    {
                        BillNo           = creditNote.Credit_Note_Number,
                        DocumentType     = "Credit Memo",
                        FiscalYear       = store.FISCAL_YEAR,
                        LocationCode     = store.INITIAL,
                        BillDate         = creditNote.Trans_Date_Ad.Value,
                        PostingTime      = creditNote.Trans_Time.Value,
                        CustomerCode     = creditNote.Customer_Id,
                        CustomerName     = creditNote.Customer_Name,
                        Vatno            = creditNote.Customer_Vat,
                        Amount           = creditNote.Total_Gross_Amount.Value,
                        Discount         = creditNote.Total_Discount.Value,
                        TaxableAmount    = creditNote.TaxableAmount,
                        NonTaxableAmount = creditNote.NonTaxableAmount,
                        TaxAmount        = creditNote.Total_Vat == null ? 0 : creditNote.Total_Vat.Value,
                        TotalAmount      = creditNote.Total_Net_Amount.Value,
                        IsBillActive     = true,
                        IsBillPrinted    = false,
                        PrintedTime      = DateTime.Now,
                        PrintedBy        = "",
                        EnteredBy        = creditNote.Created_By,
                        SyncStatus       = "Not Started",
                        SyncedDate       = DateTime.Now,
                        SyncedTime       = DateTime.Now.TimeOfDay,
                        SyncWithIrd      = false,
                        IsRealTime       = false
                    };

                    InvoiceMaterializedView invoiceMaterializedView = _context.InvoiceMaterializedView.FirstOrDefault(x => x.BillNo == creditNote.Reference_Number.Trim());
                    invoiceMaterializedView.IsBillActive          = false;
                    _context.Entry(invoiceMaterializedView).State = EntityState.Modified;

                    NavCreditMemo navCreditMemo = new NavCreditMemo()
                    {
                        id                     = creditNote.Id.ToString(),
                        number                 = creditNote.Credit_Note_Number,
                        postingno              = creditNote.Credit_Note_Number,
                        creditMemoDate         = creditNote.Trans_Date_Ad.Value.ToString("yyyy-MM-dd"),
                        customerNumber         = creditNote.MemberId,
                        customerName           = creditNote.Customer_Name,
                        vatregistrationnumber  = creditNote.Customer_Vat,
                        locationcode           = store.INITIAL,
                        accountabilitycenter   = store.INITIAL,
                        assigneduserid         = creditNote.Created_By,
                        externalDocumentNumber = creditNote.Reference_Number,
                        amountrounded          = creditNote.IsRoundup,
                        returnremarks          = creditNote.Credit_Note
                    };
                    _context.InvoiceMaterializedView.Add(view);
                    _context.SaveChanges();

                    //post to ird
                    //background task
                    BackgroundJob.Enqueue(() => SendDataToIRD(creditNote, store));
                    //Send data to NAV
                    Config config = ConfigJSON.Read();
                    if (!config.StopCreditNotePosting)
                    {
                        NavPostData navPostData = new NavPostData(_context, _mapper);
                        BackgroundJob.Enqueue(() => navPostData.PostCreditNote(navCreditMemo));
                    }

                    //for api return
                    TempData["StatusMessage"] = "Credit Note Added Successfully";
                    return(Ok(new { redirectUrl = "/CreditNote", Message = "Credit Note Added Successfully", InvoiceData = creditNote, StoreData = store }));
                }
                catch (Exception ex)
                {
                    if (ex.Message.Contains("UniqueCreditNoteNumber") || ex.InnerException.Message.Contains("UniqueCreditNoteNumber"))
                    {
                        return(await Index(creditNote));
                    }
                }
            }
            return(View(creditNote));
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> Index([FromBody] SalesInvoiceAndCustomerViewModel model)
        {
            SalesInvoiceTmp salesInvoiceTmp = model.SalesInvoice;
            Customer        customer        = model.Customer;

            if (ModelState.IsValid)
            {
                if (model.SalesInvoice.Trans_Date_Ad.Value.ToShortDateString() != DateTime.Now.ToShortDateString())
                {
                    return(StatusCode(400, "Date is not Up-to-Date !!"));
                }
                try
                {
                    //if that salesinvoice already exist, than track first
                    SalesInvoiceTmp oldData = new SalesInvoiceTmp();
                    bool            isExistOldSalesInvoice = false;
                    if (salesInvoiceTmp.Id != null)
                    {
                        oldData = await _context.SalesInvoiceTmp.FirstOrDefaultAsync(x => x.Id == salesInvoiceTmp.Id);

                        if (oldData != null)
                        {
                            isExistOldSalesInvoice = true;
                        }
                    }

                    //add membership
                    if (!string.IsNullOrEmpty(customer.Name) && !string.IsNullOrEmpty(customer.Mobile1) && customer.Is_Member == true)
                    {
                        Customer member = AddCustomer(customer);
                        //_context.SaveChanges();
                        salesInvoiceTmp.Customer_Id = member.Code;
                        salesInvoiceTmp.MemberId    = member.Membership_Number;
                    }


                    //now processed to new save invoice
                    salesInvoiceTmp.Id           = Guid.NewGuid();
                    salesInvoiceTmp.Trans_Time   = DateTime.Now.TimeOfDay;
                    salesInvoiceTmp.Division     = "Divisioin";
                    salesInvoiceTmp.Terminal     = HttpContext.Session.GetString("Terminal");
                    salesInvoiceTmp.Created_Date = DateTime.Now;
                    salesInvoiceTmp.Created_By   = User.Identity.Name;



                    _context.Add(salesInvoiceTmp);

                    foreach (var item in salesInvoiceTmp.SalesInvoiceItems)
                    {
                        item.Invoice_Id     = salesInvoiceTmp.Id;
                        item.Invoice_Number = salesInvoiceTmp.Invoice_Number;
                        _context.SalesInvoiceItemsTmp.Add(item);
                    }



                    await _context.SaveChangesAsync();

                    //if everything goes right then delete old sales invoice in background
                    if (isExistOldSalesInvoice)
                    {
                        _context.SalesInvoiceTmp.Remove(oldData);
                        _context.SaveChanges();
                    }



                    //for serverside return
                    //if (salesInvoiceTmp.Trans_Type == "Hold")
                    //    return RedirectToAction("Index");
                    //else
                    //    return RedirectToAction("Billing", new { id = salesInvoiceTmp.Id });
                    //for api return
                    if (salesInvoiceTmp.Trans_Type == "Save")
                    {
                        return(Ok(new { redirectUrl = "" }));
                    }
                    if (salesInvoiceTmp.Trans_Type == "Hold" || salesInvoiceTmp.Trans_Type == "Save")
                    {
                        return(Ok(new { redirectUrl = "/SalesInvoice/Landing" }));
                    }
                    else if (salesInvoiceTmp.Trans_Type == "Tax")
                    {
                        return(Ok(new { RedirectUrl = "/SalesInvoice/Billing/" + salesInvoiceTmp.Id + "?M=" + salesInvoiceTmp.MemberId + "&Mode=tax" }));
                    }
                    else
                    {
                        return(Ok(new { RedirectUrl = "/SalesInvoice/Billing/" + salesInvoiceTmp.Id + "?M=" + salesInvoiceTmp.MemberId }));
                    }
                }
                catch (Exception ex)
                {
                    return(StatusCode(500, ex.InnerException));
                }
            }
            return(View(salesInvoiceTmp));
        }
Ejemplo n.º 8
0
        public IActionResult CreateMembership([FromBody] Customer customer)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    customer.Code      = Guid.NewGuid().ToString();
                    customer.Is_Member = true;
                    customer.Member_Id = _context.Customer.Where(x => x.Is_Member == true && x.Member_Id != null).Select(x => x.Member_Id).DefaultIfEmpty(0).Max() + 1;
                    Store store = JsonConvert.DeserializeObject <Store>(HttpContext.Session.GetString("Store"));
                    customer.Membership_Number = store.INITIAL + "-" + Convert.ToInt32(customer.Member_Id).ToString("000000");
                    //check number series already
                    Customer isCustomerExist = _context.Customer.FirstOrDefault(x => x.Membership_Number == customer.Membership_Number);
                    if (isCustomerExist != null)
                    {
                        if (isCustomerExist.Member_Id != customer.Member_Id)
                        {
                            isCustomerExist.Member_Id             = customer.Member_Id;
                            _context.Entry(isCustomerExist).State = EntityState.Modified;
                            _context.SaveChanges();
                        }
                        return(CreateMembership(customer));
                    }
                    customer.Created_By          = User.Identity.Name;
                    customer.Registration_Date   = DateTime.Now;
                    customer.CustomerDiscGroup   = "RSP";
                    customer.CustomerPriceGroup  = "RSP";
                    customer.MembershipDiscGroup = "CATEGORY D";


                    _context.Add(customer);
                    _context.SaveChanges();

                    //update cache
                    IList <CustomerViewModel> customers;
                    if (!_cache.TryGetValue("Customers", out customers))
                    {
                        // Key not in cache, so get data.
                        customers = _context.Customer
                                    .Select(x => new CustomerViewModel
                        {
                            Address               = x.Address,
                            Barcode               = x.Barcode,
                            Code                  = x.Code,
                            CustomerDiscGroup     = x.CustomerDiscGroup,
                            CustomerPriceGroup    = x.CustomerPriceGroup,
                            Is_Member             = x.Is_Member,
                            Is_Sale_Refused       = x.Is_Sale_Refused,
                            MembershipDiscGroup   = x.MembershipDiscGroup,
                            Membership_Number     = x.Membership_Number,
                            Membership_Number_Old = x.Membership_Number_Old,
                            Member_Id             = x.Member_Id,
                            Mobile1               = x.Mobile1,
                            Name                  = x.Name,
                            Type                  = x.Type,
                            Vat = x.Vat
                        }).ToList();
                    }
                    customers.Add(new CustomerViewModel()
                    {
                        Address               = customer.Address,
                        Barcode               = customer.Barcode,
                        Code                  = customer.Code,
                        CustomerDiscGroup     = customer.CustomerDiscGroup,
                        CustomerPriceGroup    = customer.CustomerPriceGroup,
                        Is_Member             = customer.Is_Member,
                        Is_Sale_Refused       = customer.Is_Sale_Refused,
                        MembershipDiscGroup   = customer.MembershipDiscGroup,
                        Membership_Number     = customer.Membership_Number,
                        Membership_Number_Old = customer.Membership_Number_Old,
                        Member_Id             = customer.Member_Id,
                        Mobile1               = customer.Mobile1,
                        Name                  = customer.Name,
                        Type                  = customer.Type,
                        Vat = customer.Vat
                    });
                    _cache.Set("Customer", customers);

                    NavPostData navPost = new NavPostData(_context, _mapper);
                    BackgroundJob.Enqueue(() => navPost.PostCustomer());
                    return(Ok(new { StatusMessage = "Membership Created Successfully !!", Membership = customer }));
                }
                catch (Exception ex)
                {
                    if (ex.Message.Contains("'UniqueMobileNumber") || ex.InnerException.Message.Contains("UniqueMobileNumber"))
                    {
                        return(StatusCode(409, new { StatusMessage = "Mobile Number Already Register !!" }));
                    }
                    else if (ex.Message.Contains("idx_unique_member_id") || ex.InnerException.Message.Contains("idx_unique_member_id") &&
                             ex.Message.Contains("duplicate") || ex.InnerException.Message.Contains("duplicate"))
                    {
                        return(CreateMembership(customer));
                    }

                    else
                    {
                        return(StatusCode(500, new { StatusMessage = ex.Message }));
                    }

                    //TempData["StatusMessage"] = "Customer Created Successfully !!";
                }
            }
            return(StatusCode(400, new { StatusMessage = "Not Valid" }));
        }