public async Task <IActionResult> Create([Bind("transferInId,transferOrderId,transferInNumber,transferInDate,description,branchIdFrom,warehouseIdFrom,branchIdTo,warehouseIdTo,HasChild,createdAt")] TransferIn transferIn)
        {
            if (ModelState.IsValid)
            {
                //check transfer order
                TransferIn check = await _context.TransferIn.SingleOrDefaultAsync(x => x.transferOrderId.Equals(transferIn.transferOrderId));

                if (check != null)
                {
                    ViewData["StatusMessage"] = "Error. Transfer order already received. " + check.transferInNumber;

                    ViewData["transferOrderId"] = new SelectList(_context.TransferOrder, "transferOrderId", "transferOrderNumber");
                    ViewData["branchIdFrom"]    = new SelectList(_context.Branch, "branchId", "branchName");
                    ViewData["warehouseIdFrom"] = new SelectList(_context.Warehouse, "warehouseId", "warehouseName");
                    ViewData["branchIdTo"]      = new SelectList(_context.Branch, "branchId", "branchName");
                    ViewData["warehouseIdTo"]   = new SelectList(_context.Warehouse, "warehouseId", "warehouseName");


                    return(View(transferIn));
                }

                TransferOrder to = await _context.TransferOrder.Where(x => x.transferOrderId.Equals(transferIn.transferOrderId)).FirstOrDefaultAsync();

                transferIn.warehouseIdFrom = to.warehouseIdFrom;
                transferIn.warehouseIdTo   = to.warehouseIdTo;

                transferIn.warehouseFrom = await _context.Warehouse.Include(x => x.branch).SingleOrDefaultAsync(x => x.warehouseId.Equals(transferIn.warehouseIdFrom));

                transferIn.branchFrom  = transferIn.warehouseFrom.branch;
                transferIn.warehouseTo = await _context.Warehouse.Include(x => x.branch).SingleOrDefaultAsync(x => x.warehouseId.Equals(transferIn.warehouseIdTo));

                transferIn.branchTo = transferIn.warehouseTo.branch;


                to.isReceived          = true;
                to.transferOrderStatus = TransferOrderStatus.Completed;

                _context.Add(transferIn);
                await _context.SaveChangesAsync();

                //auto create transfer in line, full shipment
                List <TransferOrderLine> lines = new List <TransferOrderLine>();
                lines = _context.TransferOrderLine.Include(x => x.product).Where(x => x.transferOrderId.Equals(transferIn.transferOrderId)).ToList();
                foreach (var item in lines)
                {
                    TransferInLine line = new TransferInLine();
                    line.transferIn   = transferIn;
                    line.product      = item.product;
                    line.qty          = item.qty;
                    line.qtyInventory = line.qty * 1;

                    _context.TransferInLine.Add(line);
                    await _context.SaveChangesAsync();
                }

                return(RedirectToAction(nameof(Details), new { id = transferIn.transferInId }));
            }
            ViewData["transferOrderId"] = new SelectList(_context.TransferOrder, "transferOrderId", "transferOrderNumber", transferIn.transferOrderId);
            return(View(transferIn));
        }
Esempio n. 2
0
        public async Task <IActionResult> PostPurchaseOrderLine([FromBody] PurchaseOrderLine purchaseOrderLine)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            PurchaseOrder purchaseOrder = await _context.PurchaseOrder.Where(x => x.purchaseOrderId.Equals(purchaseOrderLine.purchaseOrderId)).FirstOrDefaultAsync();

            if (purchaseOrder.purchaseOrderStatus == PurchaseOrderStatus.Completed)
            {
                return(Json(new { success = false, message = "Error. Can not edit [Completed] order" }));
            }

            purchaseOrderLine.totalAmount = (decimal)purchaseOrderLine.qty * purchaseOrderLine.price;

            if (purchaseOrderLine.purchaseOrderLineId == string.Empty)
            {
                purchaseOrderLine.purchaseOrderLineId = Guid.NewGuid().ToString();
                _context.PurchaseOrderLine.Add(purchaseOrderLine);
                await _context.SaveChangesAsync();

                return(Json(new { success = true, message = "Add new data success." }));
            }
            else
            {
                _context.Update(purchaseOrderLine);
                await _context.SaveChangesAsync();

                return(Json(new { success = true, message = "Edit data success." }));
            }
        }
Esempio n. 3
0
        public async Task <IActionResult> Create([Bind("transferOrderId,transferOrderStatus,transferOrderNumber,transferOrderDate,description,picName,branchIdFrom,warehouseIdFrom,branchIdTo,warehouseIdTo,HasChild,createdAt")] TransferOrder transferOrder)
        {
            if (transferOrder.warehouseIdFrom == transferOrder.warehouseIdTo)
            {
                TempData["StatusMessage"] = "Error. Warehouse from and to are the same. Transfer order only working if from and to warehouse are different";
                return(RedirectToAction(nameof(Create)));
            }

            if (ModelState.IsValid)
            {
                transferOrder.warehouseFrom = await _context.Warehouse.Include(x => x.branch).SingleOrDefaultAsync(x => x.warehouseId.Equals(transferOrder.warehouseIdFrom));

                transferOrder.branchFrom = transferOrder.warehouseFrom.branch;

                transferOrder.warehouseTo = await _context.Warehouse.SingleOrDefaultAsync(x => x.warehouseId.Equals(transferOrder.warehouseIdTo));

                transferOrder.branchTo = transferOrder.warehouseTo.branch;


                _context.Add(transferOrder);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Details), new { id = transferOrder.transferOrderId }));
            }
            return(View(transferOrder));
        }
        public async Task <IActionResult> Create([Bind("accountExecutiveId,accountExecutiveName,description,phone,email,street1,street2,city,province,country,systemUserId,createdAt")] AccountExecutive accountExecutive)
        {
            if (ModelState.IsValid)
            {
                _context.Add(accountExecutive);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(accountExecutive));
        }
        public async Task <IActionResult> Create([Bind("branchId,warehouseId,warehouseName,description,street1,street2,city,province,country,createdAt")] Warehouse warehouse)
        {
            if (ModelState.IsValid)
            {
                _context.Add(warehouse);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(warehouse));
        }
Esempio n. 6
0
        public async Task <IActionResult> Create([Bind("ID,Name,DueDate,Attributes,Priority")] Project project)
        {
            if (ModelState.IsValid)
            {
                _context.Add(project);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(project));
        }
Esempio n. 7
0
        public async Task <IActionResult> Create([Bind("ClientID,BusinessName,Email,Phone,FirstName,LastName,DisplayName")] Client client)
        {
            if (ModelState.IsValid)
            {
                _context.Add(client);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(client));
        }
Esempio n. 8
0
        public async Task <IActionResult> Create([Bind("productId,productCode,productName,description,barcode,serialNumber,productType,uom,createdAt")] Product product)
        {
            if (ModelState.IsValid)
            {
                _context.Add(product);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(product));
        }
Esempio n. 9
0
        public async Task <IActionResult> Create([Bind("ratingId,ratingName,description,colorHex,createdAt")] Rating rating)
        {
            if (ModelState.IsValid)
            {
                _context.Add(rating);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(rating));
        }
Esempio n. 10
0
        public async Task <IActionResult> Create([Bind("customerId,customerName,description,size,street1,street2,city,province,country,HasChild,createdAt")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                _context.Add(customer);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Details), new { id = customer.customerId }));
            }
            return(View(customer));
        }
Esempio n. 11
0
        public async Task <IActionResult> Create([Bind("activityId,activityName,description,colorHex,createdAt")] Activity activity)
        {
            if (ModelState.IsValid)
            {
                _context.Add(activity);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(activity));
        }
Esempio n. 12
0
        public async Task <IActionResult> Create([Bind("stageId,stageName,description,colorHex,createdAt")] Stage stage)
        {
            if (ModelState.IsValid)
            {
                _context.Add(stage);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(stage));
        }
Esempio n. 13
0
        public async Task <IActionResult> Create([Bind("EmpID,FirstName,LastName,Email,Phone,EnumRoles")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                _context.Add(employee);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(employee));
        }
Esempio n. 14
0
        public async Task <IActionResult> Create([Bind("BlogId,Url")] Blog blog)
        {
            if (ModelState.IsValid)
            {
                _context.Add(blog);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(blog));
        }
Esempio n. 15
0
        public async Task <IActionResult> Create([Bind("branchId,branchName,description,street1,street2,city,province,country,createdAt,isDefaultBranch")] Branch branch)
        {
            if (ModelState.IsValid)
            {
                _context.Add(branch);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(branch));
        }
Esempio n. 16
0
        public async Task <IActionResult> Create([Bind("ContactId,OwnerID,Name,Address,City,State,Zip,Email,Status")] Contact contact)
        {
            if (ModelState.IsValid)
            {
                _context.Add(contact);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(contact));
        }
Esempio n. 17
0
        public async Task <IActionResult> Create([Bind("NoteID,Title,Content,CID")] Note note)
        {
            if (ModelState.IsValid)
            {
                _context.Add(note);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CID"] = new SelectList(_context.Clients, "ClientID", "ClientID", note.CID);
            return(View(note));
        }
        public async Task <IActionResult> Create([Bind("customerLineId,jobTitle,customerId,firstName,lastName,middleName,nickName,gender,salutation,mobilePhone,officePhone,fax,personalEmail,workEmail,createdAt")] CustomerLine customerLine)
        {
            if (ModelState.IsValid)
            {
                _context.Add(customerLine);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["customerId"] = new SelectList(_context.Customer, "customerId", "customerId", customerLine.customerId);
            return(View(customerLine));
        }
        public async Task <IActionResult> Create([Bind("purchaseOrderLineId,purchaseOrderId,productId,qty,price,discountAmount,totalAmount,createdAt")] PurchaseOrderLine purchaseOrderLine)
        {
            if (ModelState.IsValid)
            {
                _context.Add(purchaseOrderLine);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["productId"]       = new SelectList(_context.Product, "productId", "productId", purchaseOrderLine.productId);
            ViewData["purchaseOrderId"] = new SelectList(_context.PurchaseOrder, "purchaseOrderId", "purchaseOrderId", purchaseOrderLine.purchaseOrderId);
            return(View(purchaseOrderLine));
        }
Esempio n. 20
0
        public async Task <IActionResult> Create([Bind("leadId,leadName,description,street1,street2,city,province,country,isQualified,isConverted,channelId,customerId,accountExecutiveId,HasChild,createdAt")] Lead lead)
        {
            if (ModelState.IsValid)
            {
                _context.Add(lead);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["accountExecutiveId"] = new SelectList(_context.AccountExecutive, "accountExecutiveId", "accountExecutiveName", lead.accountExecutiveId);
            ViewData["channelId"]          = new SelectList(_context.Channel, "channelId", "channelName", lead.channelId);
            return(View(lead));
        }
Esempio n. 21
0
        public async Task <IActionResult> Create([Bind("opportunityLineId,opportunityId,activityId,startDate,endDate,description,createdAt")] OpportunityLine opportunityLine)
        {
            if (ModelState.IsValid)
            {
                _context.Add(opportunityLine);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["activityId"]    = new SelectList(_context.Activity, "activityId", "activityName", opportunityLine.activityId);
            ViewData["opportunityId"] = new SelectList(_context.Opportunity, "opportunityId", "opportunityName", opportunityLine.opportunityId);
            return(View(opportunityLine));
        }
        public async Task <IActionResult> Create([Bind("transferOutLineId,transferOutId,productId,qty,qtyInventory,createdAt")] TransferOutLine transferOutLine)
        {
            if (ModelState.IsValid)
            {
                _context.Add(transferOutLine);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["productId"]     = new SelectList(_context.Product, "productId", "productId", transferOutLine.productId);
            ViewData["transferOutId"] = new SelectList(_context.TransferOut, "transferOutId", "transferOutId", transferOutLine.transferOutId);
            return(View(transferOutLine));
        }
Esempio n. 23
0
        public async Task <IActionResult> Create([Bind("ID,Name,DueDate,Attributes,Priority,AssignedClientID,EmployeeID")] Project project)
        {
            if (ModelState.IsValid)
            {
                _context.Add(project);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AssignedClientID"] = new SelectList(_context.Clients, "ClientID", "BusinessName", project.AssignedClientID);
            ViewData["EmployeeID"]       = new SelectList(_context.Employees, "EmpID", "FullName", project.EmployeeID);
            return(View(project));
        }
        public async Task <IActionResult> Create([Bind("shipmentLineId,shipmentId,branchId,warehouseId,productId,qty,qtyShipment,qtyInventory,createdAt")] ShipmentLine shipmentLine)
        {
            if (ModelState.IsValid)
            {
                _context.Add(shipmentLine);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["branchId"]    = new SelectList(_context.Branch, "branchId", "branchId", shipmentLine.branchId);
            ViewData["productId"]   = new SelectList(_context.Product, "productId", "productId", shipmentLine.productId);
            ViewData["shipmentId"]  = new SelectList(_context.Shipment, "shipmentId", "shipmentId", shipmentLine.shipmentId);
            ViewData["warehouseId"] = new SelectList(_context.Warehouse, "warehouseId", "warehouseId", shipmentLine.warehouseId);
            return(View(shipmentLine));
        }
        public async Task <IActionResult> Create([Bind("receivingLineId,receivingId,branchId,warehouseId,productId,qty,qtyReceive,qtyInventory,createdAt")] ReceivingLine receivingLine)
        {
            if (ModelState.IsValid)
            {
                _context.Add(receivingLine);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["branchId"]    = new SelectList(_context.Branch, "branchId", "branchName", receivingLine.branchId);
            ViewData["productId"]   = new SelectList(_context.Product, "productId", "productCode", receivingLine.productId);
            ViewData["receivingId"] = new SelectList(_context.Receiving, "receivingId", "receivingNumber", receivingLine.receivingId);
            ViewData["warehouseId"] = new SelectList(_context.Warehouse, "warehouseId", "warehouseName", receivingLine.warehouseId);
            return(View(receivingLine));
        }
Esempio n. 26
0
        public async Task <IActionResult> Create([Bind("opportunityId,opportunityName,description,stageId,accountExecutiveId,customerId,estimatedRevenue,estimatedClosingDate,probability,ratingId,HasChild,createdAt")] Opportunity opportunity)
        {
            if (ModelState.IsValid)
            {
                if (opportunity.probability > 100)
                {
                    opportunity.probability = 100;
                }
                _context.Add(opportunity);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["accountExecutiveId"] = new SelectList(_context.AccountExecutive, "accountExecutiveId", "accountExecutiveName", opportunity.accountExecutiveId);
            ViewData["customerId"]         = new SelectList(_context.Customer, "customerId", "customerName", opportunity.customerId);
            ViewData["ratingId"]           = new SelectList(_context.Rating, "ratingId", "ratingName", opportunity.ratingId);
            ViewData["stageId"]            = new SelectList(_context.Stage, "stageId", "stageName", opportunity.stageId);
            return(View(opportunity));
        }
        public async Task <IActionResult> Create([Bind("NoteId,Title,Content,EID")] EmployeeNote employeeNote)
        {
            ViewData["Employee"] = _context.Employees.OrderBy(c => c.EmpID).ToList()
                                   .Select(n => new SelectListItem
            {
                Value = n.ToString(),
                Text  = n.ToString()
            }).ToList();
            ViewData["EmployeeId"]   = _context.Employees.OrderBy(c => c.EmpID).ToList();
            ViewData["EmployeeName"] = _context.Employees.OrderBy(c => c.FullName).ToList();
            if (ModelState.IsValid)
            {
                _context.Add(employeeNote);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(employeeNote));
        }
Esempio n. 28
0
        public async Task <IActionResult> PostTransferOrderLine([FromBody] TransferOrderLine transferOrderLine)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            TransferOrder transferOrder = await _context.TransferOrder.Where(x => x.transferOrderId.Equals(transferOrderLine.transferOrderId)).FirstOrDefaultAsync();

            if (transferOrder.transferOrderStatus == TransferOrderStatus.Completed)
            {
                return(Json(new { success = false, message = "Error. Can not edit [Completed] order" }));
            }

            if (transferOrder.isIssued == true)
            {
                return(Json(new { success = false, message = "Error. Can not edit [Open] order that already process the goods issue" }));
            }

            if (transferOrder.isReceived == true)
            {
                return(Json(new { success = false, message = "Error. Can not edit [Open] order that already process the goods receive" }));
            }

            if (transferOrderLine.transferOrderLineId == string.Empty)
            {
                transferOrderLine.transferOrderLineId = Guid.NewGuid().ToString();
                _context.TransferOrderLine.Add(transferOrderLine);
                await _context.SaveChangesAsync();

                return(Json(new { success = true, message = "Add new data success." }));
            }
            else
            {
                _context.Update(transferOrderLine);
                await _context.SaveChangesAsync();

                return(Json(new { success = true, message = "Edit data success." }));
            }
        }
        // GET: SalesOrder/Details/5
        public async Task <IActionResult> Details(string id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var salesOrder = await _context.SalesOrder
                             .Include(x => x.salesOrderLine)
                             .Include(s => s.customer)
                             .Include(x => x.branch)
                             .SingleOrDefaultAsync(m => m.salesOrderId == id);

            if (salesOrder == null)
            {
                return(NotFound());
            }

            salesOrder.totalOrderAmount    = salesOrder.salesOrderLine.Sum(x => x.totalAmount);
            salesOrder.totalDiscountAmount = salesOrder.salesOrderLine.Sum(x => x.discountAmount);
            _context.Update(salesOrder);
            await _context.SaveChangesAsync();

            return(View(salesOrder));
        }
        // GET: PurchaseOrder/Details/5
        public async Task <IActionResult> Details(string id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var purchaseOrder = await _context.PurchaseOrder
                                .Include(x => x.purchaseOrderLine)
                                .Include(p => p.vendor)
                                .Include(x => x.branch)
                                .SingleOrDefaultAsync(m => m.purchaseOrderId == id);

            if (purchaseOrder == null)
            {
                return(NotFound());
            }

            purchaseOrder.totalOrderAmount    = purchaseOrder.purchaseOrderLine.Sum(x => x.totalAmount);
            purchaseOrder.totalDiscountAmount = purchaseOrder.purchaseOrderLine.Sum(x => x.discountAmount);
            _context.Update(purchaseOrder);
            await _context.SaveChangesAsync();

            return(View(purchaseOrder));
        }