public async Task <IActionResult> Create([Bind("MoneyTransferOrderId,CashRepositoryFromCashRepositoryId,CashRepositoryIdFrom,CashRepositoryIdTo,CashRepositoryToCashRepositoryId,Description,HasChild,MoneyTransferOrderDate,MoneyTransferOrderNumber,MoneyTransferOrderStatus,PaymentAmount,createdAt,isIssued,isReceived")] MoneyTransferOrder moneyTransferOrder) { if (moneyTransferOrder.CashRepositoryIdFrom == moneyTransferOrder.CashRepositoryIdTo) { TempData["StatusMessage"] = "Σφάλμα. Το Ταμείο από και προς είναι το ίδιο. Η μεταφορά χρημάτων γίνεται μεταξύ διαφορετικών ταμείων"; return(RedirectToAction(nameof(Create))); } if (ModelState.IsValid) { moneyTransferOrder.CashRepositoryFrom = await _context.CashRepository.Include(x => x.Employee).SingleOrDefaultAsync(x => x.CashRepositoryId.Equals(moneyTransferOrder.CashRepositoryIdFrom)); moneyTransferOrder.CashRepositoryTo = await _context.CashRepository.Include(x => x.Employee).SingleOrDefaultAsync(x => x.CashRepositoryId.Equals(moneyTransferOrder.CashRepositoryIdTo)); moneyTransferOrder.MoneyTransferOrderNumber = _numberSequence.GetNumberSequence("ΕΜΧ"); _context.Add(moneyTransferOrder); await _context.SaveChangesAsync(); TempData["TransMessage"] = "Η Εντολή Μεταφοράς χρημάτων " + moneyTransferOrder.MoneyTransferOrderNumber + " έγινε με Επιτυχία"; return(RedirectToAction("Details", "MoneyTransferOrder", new { id = moneyTransferOrder.MoneyTransferOrderId })); } return(View(moneyTransferOrder)); }
public async Task <IActionResult> Create([Bind("salesOrderId,HasChild,branchId,createdAt,customerId,customerLineId,deliveryDate,description,salesOrderNumber,salesOrderStatus,salesShipmentNumber,soDate,top,totalDiscountAmount,totalOrderAmount,Invoicing,TotalProductVAT,TotalWithSpecialTax,EmployeeId,TotalBeforeDiscount,SalesOrderName,Commission")] SalesOrder salesOrder) { if (ModelState.IsValid) { string customerName = _context.Customer.Where(x => x.customerId == salesOrder.customerId).FirstOrDefault().customerName; salesOrder.salesOrderNumber = _numberSequence.GetNumberSequence("ΠΠ"); salesOrder.SalesOrderName = salesOrder.salesOrderNumber + " (" + customerName + ")"; _context.Add(salesOrder); await _context.SaveChangesAsync(); TempData["TransMessage"] = "Η Δημιουργία της Παραγγελίας Πώλησης (ΠΠ) " + salesOrder.salesOrderNumber + " έγινε με Επιτυχία"; return(RedirectToAction(nameof(Details), new { id = salesOrder.salesOrderId })); } ViewData["branchId"] = new SelectList(_context.Branch, "branchId", "branchName", salesOrder.branchId); ViewData["customerId"] = new SelectList(_context.Customer, "customerId", "customerName", salesOrder.customerId); var username = HttpContext.User.Identity.Name; if (!(HttpContext.User.IsInRole("ApplicationUser") || HttpContext.User.IsInRole("Secretary"))) { ViewData["employeeId"] = new SelectList(_context.Employee.Where(e => e.UserName == username), "EmployeeId", "DisplayName"); } else { ViewData["employeeId"] = new SelectList(_context.Employee, "EmployeeId", "DisplayName"); } return(View(salesOrder)); }
public async Task <IActionResult> Create([Bind("PaymentReceiveId,InvoiceId,IsFullPayment,PaymentAmount,PaymentDate,PaymentReceiveName,PaymentTypeId,createdAt,EmployeeId,CashRepositoryId")] PaymentReceive paymentReceive) { var username = HttpContext.User.Identity.Name; if (ModelState.IsValid) { paymentReceive.PaymentReceiveName = _numberSequence.GetNumberSequence("ΕΙΣ"); _context.Add(paymentReceive); await _context.SaveChangesAsync(); var invoice = await _context.Invoice .Include(i => i.Shipment) .Include(p => p.PaymentReceive) .SingleOrDefaultAsync(m => m.InvoiceId == paymentReceive.InvoiceId); var cashRepository = await _context.CashRepository.Where(x => x.CashRepositoryId == paymentReceive.CashRepositoryId).FirstOrDefaultAsync(); cashRepository.TotalReceipts += paymentReceive.PaymentAmount; cashRepository.Balance = cashRepository.TotalReceipts - cashRepository.TotalPayments; _context.Update(cashRepository); await _context.SaveChangesAsync(); invoice.totalPaymentReceive = invoice.PaymentReceive.Sum(x => x.PaymentAmount); invoice.InvoiceBalance = invoice.totalOrderAmount - invoice.totalPaymentReceive; if (invoice.InvoiceBalance == 0) { invoice.Paid = true; } _context.Update(invoice); await _context.SaveChangesAsync(); return(RedirectToAction("Details", "Invoice", new { id = paymentReceive.InvoiceId })); //return RedirectToAction(nameof(Index)); } var query = from Invoice in _context.Invoice select new { Invoice.InvoiceId, description = (Invoice.InvoiceNumber + " (" + Invoice.customerName + ")"), Invoice.Paid }; ViewData["InvoiceId"] = new SelectList(query.Where(x => x.Paid == false), "InvoiceId", "description", paymentReceive.InvoiceId); ViewData["PaymentTypeId"] = new SelectList(_context.PaymentType, "PaymentTypeId", "PaymentTypeName", paymentReceive.PaymentTypeId); ViewData["employeeId"] = new SelectList(_context.Employee, "EmployeeId", "DisplayName"); ViewData["CashRepositoryId"] = new SelectList(_context.CashRepository, "CashRepositoryId", "CashRepositoryName"); if (!(HttpContext.User.IsInRole("ApplicationUser") || HttpContext.User.IsInRole("Secretary"))) { ViewData["EmployeeId"] = new SelectList(_context.Employee.Where(x => x.PaymentReceiver == true && x.UserName == username), "EmployeeId", "DisplayName"); ViewData["CashRepositoryId"] = new SelectList(_context.CashRepository.Where(x => x.Employee.UserName == username), "CashRepositoryId", "CashRepositoryName"); } return(View(paymentReceive)); }
public IActionResult Insert([FromBody] CrudViewModel <GoodsReceivedNote> payload) { GoodsReceivedNote goodsReceivedNote = payload.value; goodsReceivedNote.GoodsReceivedNoteName = _numberSequence.GetNumberSequence("GRN"); _context.GoodsReceivedNote.Add(goodsReceivedNote); _context.SaveChanges(); return(Ok(goodsReceivedNote)); }
public IActionResult Insert([FromBody] CrudViewModel <Shipment> payload) { Shipment shipment = payload.value; shipment.ShipmentName = _numberSequence.GetNumberSequence("DO"); _context.Shipment.Add(shipment); _context.SaveChanges(); return(Ok(shipment)); }
public IActionResult Insert([FromBody] CrudViewModel <Bill> payload) { Bill bill = payload.value; bill.BillName = _numberSequence.GetNumberSequence("BILL"); _context.Bill.Add(bill); _context.SaveChanges(); return(Ok(bill)); }
public IActionResult Insert([FromBody] CrudViewModel <PaymentReceive> payload) { PaymentReceive paymentReceive = payload.value; paymentReceive.PaymentReceiveName = _numberSequence.GetNumberSequence("PAYRCV"); _context.PaymentReceive.Add(paymentReceive); _context.SaveChanges(); return(Ok(paymentReceive)); }
public IActionResult Insert([FromBody] CrudViewModel <Invoice> payload) { Invoice invoice = payload.value; invoice.InvoiceName = _numberSequence.GetNumberSequence("INV"); _context.Invoice.Add(invoice); _context.SaveChanges(); return(Ok(invoice)); }
public IActionResult Insert([FromBody] CrudViewModel <PaymentVoucher> payload) { PaymentVoucher paymentVoucher = payload.value; paymentVoucher.PaymentVoucherName = _numberSequence.GetNumberSequence("PAYVCH"); _context.PaymentVoucher.Add(paymentVoucher); _context.SaveChanges(); return(Ok(paymentVoucher)); }
public IActionResult Insert([FromBody] CrudViewModel <PaymentVoucher> payload) { PaymentVoucher value = payload.value; value.PaymentVoucherName = _numberSequence.GetNumberSequence("PAYVCH"); var result = _functionalService.Insert <PaymentVoucher>(value); value = (PaymentVoucher)result.Data; return(Ok(value)); }
public IActionResult Insert([FromBody] CrudViewModel <PaymentReceive> payload) { PaymentReceive paymentReceive = payload.value; paymentReceive.PaymentReceiveName = _numberSequence.GetNumberSequence("PAYRCV"); var result = _functionalService.Insert <PaymentReceive>(paymentReceive); paymentReceive = (PaymentReceive)result.Data; return(Ok(paymentReceive)); }
public IActionResult Insert([FromBody] CrudViewModel <Invoice> payload) { Invoice value = payload.value; value.InvoiceName = _numberSequence.GetNumberSequence("INV"); var result = _functionalService.Insert <Invoice>(value); value = (Invoice)result.Data; return(Ok(value)); }
public IActionResult Insert([FromBody] CrudViewModel <General> payload) { General value = payload.value; value.GeneralName = _numberSequence.GetNumberSequence("GEN"); var result = _functionalService.Insert <General>(value); value = (General)result.Data; return(Ok(value)); }
public IActionResult Insert([FromBody] CrudViewModel <SalesOrder> payload) { SalesOrder salesOrder = payload.value; salesOrder.SalesOrderName = _numberSequence.GetNumberSequence("SO"); _context.SalesOrder.Add(salesOrder); _context.SaveChanges(); this.UpdateSalesOrder(salesOrder.SalesOrderId); return(Ok(salesOrder)); }
public IActionResult Insert([FromBody] CrudViewModel <Car> payload) { Car value = payload.value; value.CarName = _numberSequence.GetNumberSequence("CAR"); var result = _functionalService.Insert <Car>(value); value = (Car)result.Data; return(Ok(value)); }
public IActionResult Insert([FromBody] CrudViewModel <GoodsReceivedNote> payload) { GoodsReceivedNote value = payload.value; value.GoodsReceivedNoteName = _numberSequence.GetNumberSequence("GRN"); var result = _functionalService.Insert <GoodsReceivedNote>(value); value = (GoodsReceivedNote)result.Data; return(Ok(value)); }
public IActionResult Insert([FromBody] CrudViewModel <Bill> payload) { Bill value = payload.value; value.BillName = _numberSequence.GetNumberSequence("BILL"); var result = _functionalService.Insert <Bill>(value); value = (Bill)result.Data; return(Ok(value)); }
public IActionResult Insert([FromBody] CrudViewModel <MeetingRoom> payload) { MeetingRoom value = payload.value; value.MeetingRoomName = _numberSequence.GetNumberSequence("ROOM"); var result = _functionalService.Insert <MeetingRoom>(value); value = (MeetingRoom)result.Data; return(Ok(value)); }
public IActionResult Insert([FromBody] CrudViewModel <PurchaseOrder> payload) { PurchaseOrder purchaseOrder = payload.value; purchaseOrder.PurchaseOrderName = _numberSequence.GetNumberSequence("PO"); _context.PurchaseOrder.Add(purchaseOrder); _context.SaveChanges(); this.UpdatePurchaseOrder(purchaseOrder.PurchaseOrderId); return(Ok(purchaseOrder)); }
public IActionResult Insert([FromBody] CrudViewModel <Shipment> payload) { Shipment value = payload.value; value.ShipmentName = _numberSequence.GetNumberSequence("DO"); var result = _functionalService.Insert <Shipment>(value); value = (Shipment)result.Data; return(Ok(value)); }
public IActionResult Insert([FromBody] CrudViewModel <PurchaseOrder> payload) { PurchaseOrder value = payload.value; value.PurchaseOrderName = _numberSequence.GetNumberSequence("PO"); var result = _functionalService.Insert <PurchaseOrder>(value); value = (PurchaseOrder)result.Data; this.UpdatePurchaseOrder(value.PurchaseOrderId); return(Ok(value)); }
public async Task <IActionResult> Create([Bind("VendorPaymentId,CashRepositoryId,EmployeeId,PaymentAmount,PaymentDate,PaymentNumber,PaymentTypeId,createdAt,purchaseOrderId")] VendorPayment vendorPayment) { var username = HttpContext.User.Identity.Name; var cashrepository = await _context.CashRepository.Where(x => x.CashRepositoryId == vendorPayment.CashRepositoryId).FirstOrDefaultAsync(); if (cashrepository.Balance < vendorPayment.PaymentAmount) { TempData["StatusMessage"] = "Σφάλμα. Υπάρχει πρόβλημα στα ταμειακά διαθέσιμα. Το υπόλοιπο του ταμείου σας (" + cashrepository.Balance + "€), δεν επαρκεί για να καλύψει το ποσόν της πληρωμής(" + vendorPayment.PaymentAmount + "€). Αλλάξτε ταμείο ή πληρώστε λιγότερα."; return(RedirectToAction(nameof(Create))); } if (ModelState.IsValid) { vendorPayment.PaymentNumber = _numberSequence.GetNumberSequence("ΠΛΠ"); _context.Add(vendorPayment); await _context.SaveChangesAsync(); var purchaseorder = await _context.PurchaseOrder .Include(p => p.vendorPayment) .SingleOrDefaultAsync(m => m.purchaseOrderId == vendorPayment.purchaseOrderId); purchaseorder.totalVendorPayment = purchaseorder.vendorPayment.Sum(x => x.PaymentAmount); purchaseorder.InvoiceBalance = purchaseorder.totalOrderAmount - purchaseorder.totalVendorPayment; if (purchaseorder.InvoiceBalance == 0) { purchaseorder.Paid = true; } _context.Update(purchaseorder); await _context.SaveChangesAsync(); return(RedirectToAction("Details", "purchaseOrder", new { id = purchaseorder.purchaseOrderId })); } var query = from PurchaseOrder in _context.PurchaseOrder select new { PurchaseOrder.purchaseOrderId, description = (PurchaseOrder.purchaseOrderNumber + " (" + PurchaseOrder.vendor.vendorName + ")"), PurchaseOrder.Paid }; ViewData["purchaseOrderId"] = new SelectList(query.Where(x => x.Paid == false), "purchaseOrderId", "description", vendorPayment.purchaseOrderId); ViewData["PaymentTypeId"] = new SelectList(_context.PaymentType, "PaymentTypeId", "PaymentTypeName", vendorPayment.PaymentTypeId); ViewData["employeeId"] = new SelectList(_context.Employee, "EmployeeId", "DisplayName"); ViewData["CashRepositoryId"] = new SelectList(_context.CashRepository, "CashRepositoryId", "CashRepositoryName"); if (!(HttpContext.User.IsInRole("ApplicationUser") || HttpContext.User.IsInRole("Secretary"))) { ViewData["EmployeeId"] = new SelectList(_context.Employee.Where(x => x.PaymentReceiver == true && x.UserName == username), "EmployeeId", "DisplayName"); ViewData["CashRepositoryId"] = new SelectList(_context.CashRepository.Where(x => x.Employee.UserName == username), "CashRepositoryId", "CashRepositoryName"); } return(View(vendorPayment)); }
public async Task <IActionResult> Create([Bind("ProductionOrderId,Description,HasChild,Notes,ProductionOrderDate,ProductionOrderStatus,RequiredDeliveryDate,createdAt,ProductionOrderNumber,branchId")] ProductionOrder productionOrder) { if (ModelState.IsValid) { productionOrder.ProductionOrderNumber = _numberSequence.GetNumberSequence("ΠΠΡ"); _context.Add(productionOrder); await _context.SaveChangesAsync(); TempData["TransMessage"] = "Η Δημιουργία της Παραγγελίας Παραγωγής (ΠΠΡ) " + productionOrder.ProductionOrderNumber + " έγινε με Επιτυχία"; return(RedirectToAction(nameof(Details), new { id = productionOrder.ProductionOrderId })); } ViewData["branchId"] = new SelectList(_context.Branch, "branchId", "branchName", productionOrder.branchId); return(View(productionOrder)); }
public async Task <IActionResult> Insert([FromBody] CrudViewModel <UserProfile> payload) { UserProfile register = payload.value; if (register.Password.Equals(register.ConfirmPassword)) { ApplicationUser user = new ApplicationUser() { Email = register.Email, UserName = register.Email, EmailConfirmed = true }; var result = await _userManager.CreateAsync(user, register.Password); if (result.Succeeded) { register.EmployeeCode = _numberSequence.GetNumberSequence("EMP"); register.Password = user.PasswordHash; register.ConfirmPassword = user.PasswordHash; register.ApplicationUserId = user.Id; _functionalService.Insert <UserProfile>(register); } } return(Ok(register)); }
public async Task <IActionResult> Create([Bind("EmployeePaymentId,PaymentNumber,PaymentDate,PaymentTypeId,PaymentAmount,EmployeeId,CashRepositoryId,createdAt")] EmployeePayment employeePayment) { var username = HttpContext.User.Identity.Name; var cashrepository = await _context.CashRepository.Where(x => x.CashRepositoryId == employeePayment.CashRepositoryId).FirstOrDefaultAsync(); if (cashrepository.Balance < employeePayment.PaymentAmount) { TempData["StatusMessage"] = "Σφάλμα. Υπάρχει πρόβλημα στα ταμειακά διαθέσιμα. Το υπόλοιπο του ταμείου σας (" + cashrepository.Balance + "€), δεν επαρκεί για να καλύψει το ποσόν της πληρωμής(" + employeePayment.PaymentAmount + "€). Αλλάξτε ταμείο ή πληρώστε λιγότερα."; return(RedirectToAction(nameof(Create))); } if (ModelState.IsValid) { employeePayment.PaymentNumber = _numberSequence.GetNumberSequence("ΠΛΣ"); _context.Add(employeePayment); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CashRepositoryId"] = new SelectList(_context.CashRepository, "CashRepositoryId", "CashRepositoryName", employeePayment.CashRepositoryId); ViewData["EmployeeId"] = new SelectList(_context.Employee, "EmployeeId", "DisplayName", employeePayment.EmployeeId); ViewData["PaymentTypeId"] = new SelectList(_context.PaymentType, "PaymentTypeId", "PaymentTypeName", employeePayment.PaymentTypeId); return(View(employeePayment)); }
public async Task <IActionResult> Create([Bind("shipmentId,HasChild,branchId,createdAt,customerId,customerPO,expeditionMode,expeditionType,invoiceNumber,salesOrderId,shipmentDate,shipmentNumber,warehouseId,EmployeeId")] Shipment shipment) { if (shipment.salesOrderId == "0" || shipment.warehouseId == "0") { TempData["StatusMessage"] = "Σφάλμα. Η εντολή πώλησης ή η αποθήκη δεν είναι έγκυρη. Επιλέξτε έγκυρη παραγγελία και αποθήκη πωλήσεων"; return(RedirectToAction(nameof(Create))); } if (ModelState.IsValid) { //check sales order Shipment check = await _context.Shipment .Include(x => x.salesOrder) .Include(x => x.Employee) .SingleOrDefaultAsync(x => x.salesOrderId.Equals(shipment.salesOrderId)); if (check != null) { ViewData["salesOrderId"] = new SelectList(_context.SalesOrder.Where(x => x.salesOrderStatus == SalesOrderStatus.Open), "salesOrderId", "SalesOrderName"); ViewData["StatusMessage"] = "Σφάλμα. Η εντολή πώλησης έχει ήδη αποσταλεί. " + check.shipmentNumber; ViewData["branchId"] = new SelectList(_context.Branch, "branchId", "branchName"); ViewData["customerId"] = new SelectList(_context.Customer, "customerId", "customerName"); ViewData["warehouseId"] = new SelectList(_context.Warehouse, "warehouseId", "warehouseName"); ViewData["employeeId"] = new SelectList(_context.Employee, "EmployeeId", "DisplayName"); return(View(shipment)); } //check stock bool isStockOK = true; string productList = ""; List <SalesOrderLine> stocklines = new List <SalesOrderLine>(); stocklines = _context.SalesOrderLine .Include(x => x.Product) .Where(x => x.SalesOrderId.Equals(shipment.salesOrderId)).ToList(); foreach (var item in stocklines) { VMStock stock = _netcoreService.GetStockByProductAndWarehouse(item.ProductId, shipment.warehouseId); if (stock != null) { if (stock.QtyOnhand < item.Qty) { isStockOK = false; productList = productList + " [" + item.Product.productCode + "] "; } } else { isStockOK = false; } } if (!isStockOK) { TempData["StatusMessage"] = "Σφάλμα. Υπάρχει πρόβλημα στην ποσότητα αποθεμάτων, ελέγξτε το απόθεμά σας. " + productList; return(RedirectToAction(nameof(Create))); } shipment.warehouse = await _context.Warehouse.Include(x => x.branch).SingleOrDefaultAsync(x => x.warehouseId.Equals(shipment.warehouseId)); shipment.branch = shipment.warehouse.branch; shipment.salesOrder = await _context.SalesOrder.Include(x => x.customer).SingleOrDefaultAsync(x => x.salesOrderId.Equals(shipment.salesOrderId)); shipment.customer = shipment.salesOrder.customer; //change status of salesorder shipment.salesOrder.salesOrderStatus = SalesOrderStatus.Completed; _context.Update(shipment.salesOrder); shipment.shipmentNumber = _numberSequence.GetNumberSequence("ΔΑ"); _context.Add(shipment); await _context.SaveChangesAsync(); //auto create shipment line, full shipment List <SalesOrderLine> solines = new List <SalesOrderLine>(); solines = _context.SalesOrderLine.Include(x => x.Product).Where(x => x.SalesOrderId.Equals(shipment.salesOrderId)).ToList(); foreach (var item in solines) { ShipmentLine line = new ShipmentLine(); line.shipment = shipment; line.product = item.Product; line.qty = item.Qty; line.qtyShipment = item.Qty; line.qtyInventory = line.qtyShipment * -1; line.branchId = shipment.branchId; line.warehouseId = shipment.warehouseId; _context.ShipmentLine.Add(line); await _context.SaveChangesAsync(); } TempData["TransMessage"] = "Η Δημιουργία της Αποστολής " + shipment.shipmentNumber + " έγινε με Επιτυχία"; return(RedirectToAction(nameof(Details), new { id = shipment.shipmentId })); } ViewData["branchId"] = new SelectList(_context.Branch, "branchId", "branchName", shipment.branchId); ViewData["customerId"] = new SelectList(_context.Customer, "customerId", "customerName", shipment.customerId); ViewData["salesOrderId"] = new SelectList(_context.SalesOrder.Where(x => x.salesOrderStatus == SalesOrderStatus.Open), "salesOrderId", "SalesOrderName", shipment.salesOrderId); ViewData["warehouseId"] = new SelectList(_context.Warehouse, "warehouseId", "warehouseName", shipment.warehouseId); ViewData["employeeId"] = new SelectList(_context.Employee, "EmployeeId", "DisplayName", shipment.EmployeeId); return(View(shipment)); }
public async Task <IActionResult> Create([Bind("ProductionId,HasChild,ProductionDate,ProductionNumber,ProductionOrderId,createdAt,warehouseId,ProductionStatus,Description,Notes")] Production production) { if (production.ProductionOrderId == "0" || production.warehouseId == "0") { TempData["StatusMessage"] = "Σφάλμα. Η εντολή παραγωγής ή η αποθήκη δεν είναι έγκυρη. Επιλέξτε έγκυρη παραγγελία και αποθήκη παραγωγής"; return(RedirectToAction(nameof(Create))); } if (ModelState.IsValid) { var polines = from ProductionOrderLine in _context.ProductionOrderLine join Product in _context.Product on ProductionOrderLine.ProductId equals Product.productId join ProductLine in _context.ProductLine on Product.productId equals ProductLine.ProductId join Product_1 in _context.Product on new { ComponentId = ProductLine.ComponentId } equals new { ComponentId = Product_1.productId } group new { ProductLine, ProductionOrderLine, Product_1 } by new { ProductLine.ComponentId, ProductionOrderLine.ProductionOrderId, Product_1.productCode } into g select new { g.Key.ProductionOrderId, g.Key.ComponentId, g.Key.productCode, ComponentQty = (decimal?)g.Sum(p => p.ProductionOrderLine.Qty * System.Convert.ToSingle(p.ProductLine.Percentage)) }; polines = polines.Where(x => x.ProductionOrderId == production.ProductionOrderId); //check production order Production check = await _context.Production .Include(x => x.ProductionOrder) .Include(x => x.warehouse) .SingleOrDefaultAsync(x => x.ProductionOrderId.Equals(production.ProductionOrderId)); if (check != null) { ViewData["ProductionOrderId"] = new SelectList(_context.ProductionOrder.Where(x => x.ProductionOrderStatus == ProductionOrderStatus.Open), "ProductionOrderId", "ProductionNumber"); ViewData["StatusMessage"] = "Σφάλμα. Η εντολή παραγωγής έχει ήδη αποσταλεί. " + check.ProductionNumber; ViewData["warehouseId"] = new SelectList(_context.Warehouse, "warehouseId", "warehouseName"); return(View(production)); } //check stock bool isStockOK = true; string productList = ""; foreach (var item in polines) { VMStock stock = _netcoreService.GetStockByProductAndWarehouse(item.ComponentId, production.warehouseId); if (stock != null) { if (stock.QtyOnhand < System.Convert.ToSingle(item.ComponentQty)) { isStockOK = false; productList = productList + " [" + item.productCode + "] "; } } else { isStockOK = false; } } if (!isStockOK) { TempData["StatusMessage"] = "Σφάλμα. Υπάρχει πρόβλημα στην ποσότητα αποθεμάτων, ελέγξτε το απόθεμά σας. " + productList; return(RedirectToAction(nameof(Create))); } //change status of salesorder var pro = _context.ProductionOrder.Where(x => x.ProductionOrderId == production.ProductionOrderId).FirstOrDefault(); pro.ProductionOrderStatus = ProductionOrderStatus.Completed; _context.Update(pro); production.ProductionNumber = _numberSequence.GetNumberSequence("ΠΑΡ"); _context.Add(production); await _context.SaveChangesAsync(); //*auto create production line, full production foreach (var item in polines) { Product prod = _context.Product.Where(x => x.productId == item.ComponentId).FirstOrDefault(); ProductionLine line = new ProductionLine(); line.Production = production; line.product = prod; line.warehouse = production.warehouse; line.branch = production.ProductionOrder.branch; line.qty = System.Convert.ToInt32(item.ComponentQty); line.branchId = production.ProductionOrder.branchId; line.warehouseId = production.warehouseId; _context.ProductionLine.Add(line); await _context.SaveChangesAsync(); } TempData["TransMessage"] = "Η Δημιουργία της Παραγωγής " + production.ProductionNumber + " έγινε με Επιτυχία"; ViewData["ProductionOrderId"] = new SelectList(_context.ProductionOrder, "ProductionOrderId", "ProductionOrderNumber", production.ProductionOrderId); return(RedirectToAction(nameof(Details), new { id = production.ProductionId })); } ViewData["warehouseId"] = new SelectList(_context.Warehouse, "warehouseId", "warehouseName", production.warehouseId); return(View(production)); }
public async Task <IActionResult> Create([Bind("InvoiceId,HasChild,InvoiceDate,InvoiceNumber,createdAt,shipmentId,Finalized,CustomerCity,CustomerCountry,CustomerPostCode,CustomerStreet,CustomerTaxOffice,CustomerVATRegNumber,EmployeeName,Fax,OfficePhone,PostalCode,TaxOffice,VATNumber,branchName,city,customerName,description,email,street1,Comments,TotalBeforeDiscount,TotalProductVAT,totalDiscountAmount,totalOrderAmount,CustomerCompanyActivity,CustomerFax,CustomerMobilePhone,CustomerOfficePhone,CustomerWorkEmail,Paid,totalPaymentReceive,InvoiceBalance")] Invoice invoice) { if (ModelState.IsValid) { //check Invoice Invoice check = await _context.Invoice.Include(x => x.Shipment) .SingleOrDefaultAsync(x => x.shipmentId.Equals(invoice.shipmentId)); if (check != null) { ViewData["StatusMessage"] = "Σφάλμα. Το Τιμολόγιο έχει ήδη δημιουργηθεί. " + check.InvoiceNumber; ViewData["shipmentId"] = new SelectList(_context.Shipment, "shipmentId", "shipmentNumber"); return(View(invoice)); } _context.Add(invoice); invoice.InvoiceNumber = _numberSequence.GetNumberSequence("ΔΑΠ"); Shipment ship = await _context.Shipment.Where(x => x.shipmentId == invoice.shipmentId).FirstOrDefaultAsync(); ship.invoiceNumber = invoice.InvoiceNumber; _context.Update(ship); var query = from Invoice in _context.Invoice join Shipment in _context.Shipment on Invoice.shipmentId equals Shipment.shipmentId join SalesOrder in _context.SalesOrder on Shipment.salesOrderId equals SalesOrder.salesOrderId join Customer in _context.Customer on new { Shipment.customerId, Column1 = SalesOrder.customerId } equals new { Customer.customerId, Column1 = Customer.customerId } join Employee in _context.Employee on Customer.EmployeeId equals Employee.EmployeeId join Branch in _context.Branch on Shipment.branchId equals Branch.branchId join CustomerLine in _context.CustomerLine on SalesOrder.customerLineId equals CustomerLine.customerLineId select new { Branch.branchName, Branch.description, Branch.street1, Branch.PostalCode, Branch.city, Branch.OfficePhone, Branch.Fax, Branch.email, Branch.VATNumber, Branch.TaxOffice, EmployeeName = Employee.DisplayName, SalesOrder.deliveryDate, Customer.customerName, Customer.CompanyActivity, customerStreet1 = CustomerLine.street1, customerPostCode = CustomerLine.PostCode, customerCity = CustomerLine.city, customerCountry = CustomerLine.country, customerVATRegNumber = Customer.VATRegNumber, customerTaxOffice = Customer.TaxOffice, CustomerEmail = Customer.workEmail, CustomerOfficePhone = Customer.officePhone, CustomerMobilePhone = Customer.mobilePhone, CustomerFax = Customer.fax, Invoice.InvoiceId, Comments = SalesOrder.description, SalesOrder.salesOrderNumber, SalesOrder.totalDiscountAmount, SalesOrder.totalOrderAmount, SalesOrder.TotalProductVAT, SalesOrder.TotalWithSpecialTax, SalesOrder.TotalBeforeDiscount, SalesOrder.Invoicing }; var inv = query.Where(x => x.InvoiceId == invoice.InvoiceId).FirstOrDefault(); if (inv.Invoicing) { invoice.InvoiceNumber = _numberSequence.GetNumberSequence("ΤΔΑ"); } invoice.branchName = inv.branchName; invoice.description = inv.description; invoice.VATNumber = inv.VATNumber; invoice.city = inv.city; invoice.CustomerCity = inv.customerCity; invoice.CustomerCountry = inv.customerCountry; invoice.customerName = inv.customerName; invoice.CustomerCompanyActivity = inv.CompanyActivity; invoice.CustomerPostCode = inv.customerPostCode; invoice.CustomerStreet = inv.customerStreet1; invoice.CustomerTaxOffice = inv.customerTaxOffice; invoice.CustomerVATRegNumber = inv.customerVATRegNumber; invoice.CustomerFax = inv.CustomerFax; invoice.CustomerMobilePhone = inv.CustomerMobilePhone; invoice.CustomerWorkEmail = inv.CustomerEmail; invoice.CustomerOfficePhone = inv.CustomerOfficePhone; invoice.email = inv.email; invoice.EmployeeName = inv.EmployeeName; invoice.Fax = inv.Fax; invoice.InvoiceDate = inv.deliveryDate; invoice.OfficePhone = inv.OfficePhone; invoice.PostalCode = inv.PostalCode; invoice.street1 = inv.street1; invoice.TaxOffice = inv.TaxOffice; invoice.TotalBeforeDiscount = inv.TotalBeforeDiscount; invoice.totalDiscountAmount = inv.totalDiscountAmount; invoice.totalOrderAmount = inv.totalOrderAmount; invoice.TotalProductVAT = inv.TotalProductVAT; await _context.SaveChangesAsync(); //auto create shipment line, full shipment List <SalesOrderLine> solines = new List <SalesOrderLine>(); var salesOrderId = _context.Shipment.Where(x => x.shipmentId == invoice.shipmentId).FirstOrDefault().salesOrderId; solines = _context.SalesOrderLine.Include(x => x.Product).Where(x => x.SalesOrderId.Equals(salesOrderId)).ToList(); foreach (var item in solines) { InvoiceLine line = new InvoiceLine(); line.Discount = item.Discount; line.DiscountAmount = item.DiscountAmount; line.InvoiceId = invoice.InvoiceId; line.InvoiceLineId = item.SalesOrderLineId; line.Price = item.Price; line.Product = item.Product; line.ProductId = item.ProductId; line.ProductVAT = item.ProductVAT; line.ProductVATAmount = item.ProductVATAmount; line.Qty = item.Qty; line.SpecialTaxAmount = item.SpecialTaxAmount; line.SpecialTaxDiscount = item.SpecialTaxDiscount; line.TotalAfterDiscount = item.TotalAfterDiscount; line.TotalAmount = item.TotalAmount; line.TotalBeforeDiscount = item.TotalBeforeDiscount; line.TotalSpecialTaxAmount = item.TotalSpecialTaxAmount; line.TotalWithSpecialTax = item.TotalWithSpecialTax; line.UnitCost = item.UnitCost; _context.InvoiceLine.Add(line); await _context.SaveChangesAsync(); } return(RedirectToAction(nameof(Details), new { id = invoice.InvoiceId })); } var shipment = from Shipment in _context.Shipment join Customer in _context.Customer on Shipment.customerId equals Customer.customerId select new { Shipment.shipmentId, ShipmentName = (Shipment.shipmentNumber + " ( " + Customer.customerName + ")") }; ViewData["shipmentId"] = new SelectList(shipment, "shipmentId", "ShipmentName"); return(View(invoice)); }