public void autoPurchOrders() { Stock_Management stockSettings = new Stock_Management(); List <SP_GetAuto_Purchase_Products> AutoPurchProds = new List <SP_GetAuto_Purchase_Products>(); List <PRODUCT> allProducts = null; string success = "Err"; try { stockSettings = Handler.getStockSettings(); if (stockSettings.AutoPurchase == true) { if (stockSettings.NxtOrderdDate < DateTime.Now) { if (stockSettings.AutoPurchaseProducts == true) { AutoPurchProds = Handler.getAutoPurchOrdProds(); } else { allProducts = Handler.getAllProducts(); foreach (PRODUCT prod in allProducts) { SP_GetAuto_Purchase_Products purchProd = new SP_GetAuto_Purchase_Products(); purchProd.ProductID = prod.ProductID; purchProd.Name = prod.Name; purchProd.ProductType = prod.ProductType; purchProd.Qty = stockSettings.PurchaseQty; AutoPurchProds.Add(purchProd); } } List <Supplier> supps = Handler.getSuppliers(); foreach (Supplier sup in supps) { Order order = new Order(); order.supplierID = sup.supplierID; List <Order_DTL> orderDTLs = new List <Order_DTL>(); List <OrderViewModel> outOrders = Handler.getOutStandingOrders(); foreach (SP_GetAuto_Purchase_Products prod in AutoPurchProds) { bool add = true; //check if the product is not alread on order foreach (OrderViewModel outOrder in outOrders) { List <OrderViewModel> outOrderProducts = Handler.getProductOrderDL(outOrder.OrderID.ToString()); foreach (OrderViewModel outOrderDL in outOrderProducts) { if (outOrderDL.ProductID == prod.ProductID) { add = false; } } } if (add == true) { if (prod.ProductType == "A") { SP_GetAllAccessories prodDetails = Handler.selectAccessory(prod.ProductID); if (prodDetails.supplierID == sup.supplierID && prodDetails.Qty < stockSettings.LowStock) { Order_DTL newOrderProduct = new Order_DTL(); newOrderProduct.Qty = prod.Qty; newOrderProduct.ProductID = prod.ProductID; orderDTLs.Add(newOrderProduct); } } else if (prod.ProductType == "T") { SP_GetAllTreatments prodDetails = Handler.selectTreatment(prod.ProductID); if (prodDetails.supplierID == sup.supplierID && prodDetails.Qty < stockSettings.LowStock) { Order_DTL newOrderProduct = new Order_DTL(); newOrderProduct.Qty = prod.Qty; newOrderProduct.ProductID = prod.ProductID; orderDTLs.Add(newOrderProduct); } } } } if (orderDTLs.Count > 0) { success = newPurchaseOrder(order, orderDTLs); if (success != "Err") { stockSettings.NxtOrderdDate = updateAutoOrderDate(stockSettings.AutoPurchaseFrequency); Handler.updateStockSettings(stockSettings); //send manager confirmation email Supplier supp = Handler.getSupplier(order.supplierID); //send an email notification var body = new System.Text.StringBuilder(); body.AppendFormat("Hello Mnager,"); body.AppendLine(@""); body.AppendLine(@"Please review the auto purchase order request sent to " + sup.supplierName + " at the link below"); body.AppendLine(@""); body.AppendLine(@"http://sict-iis.nmmu.ac.za/beauxdebut/Manager/Products.aspx?Action=ViewOrder&OrderID=" + success); body.AppendLine(@""); body.AppendLine(@"The Next Auto Purchase request will occur on " + stockSettings.NxtOrderdDate.ToString("dd MMM yyyy")); body.AppendLine(@""); body.AppendLine(@"Regards,"); body.AppendLine(@""); body.AppendLine(@"The Cheveux Team"); sendEmailAlert(Handler.getManagerContact().Email, "Manager", "New Auto Purchase Order Request", body.ToString(), "Cheveux"); } else { stockSettings.NxtOrderdDate = updateAutoOrderDate(stockSettings.AutoPurchaseFrequency); Handler.updateStockSettings(stockSettings); //send manager error email Supplier supp = Handler.getSupplier(order.supplierID); //send an email notification var body = new System.Text.StringBuilder(); body.AppendFormat("Hello Mnager,"); body.AppendLine(@""); body.AppendLine(@"A failed auto purchase order request for supplier " + sup.supplierName + " occurred at " + DateTime.Now.ToString("HH:mm dd MMM yyyy")); body.AppendLine(@""); body.AppendLine(@"Please contact admin"); body.AppendLine(@""); body.AppendLine(@"The Next Auto Purchase request will occur on " + stockSettings.NxtOrderdDate.ToString("dd MMM yyyy")); body.AppendLine(@""); body.AppendLine(@"Regards,"); body.AppendLine(@""); body.AppendLine(@"The Cheveux Team"); sendEmailAlert(Handler.getManagerContact().Email, "Manager", "New Auto Purchase Order Request", body.ToString(), "Cheveux"); logAnError("Error making Auto Purchse Order"); success = ""; } } } } else { success = ""; } } else { success = ""; } } catch (Exception err) { logAnError("Error making Auto Purchse Order: " + err); } if (success == "Err") { logAnError("Error making Auto Purchse Order"); //send an email notification var body = new System.Text.StringBuilder(); body.AppendFormat("Hello Mnager,"); body.AppendLine(@""); body.AppendLine(@"A faild auto purchase order request ocourde at " + DateTime.Now.ToString("HH:mm dd MMM yyyy")); body.AppendLine(@""); body.AppendLine(@"Please contact admin"); body.AppendLine(@""); body.AppendLine(@"Regards,"); body.AppendLine(@""); body.AppendLine(@"The Cheveux Team"); sendEmailAlert(Handler.getManagerContact().Email, "Manager", "New Auto Purchase Order Request", body.ToString(), "Cheveux"); } }
public bool newProductOrderDL(Order_DTL newOrderDL) { return(db.newProductOrderDL(newOrderDL)); }
public string newPurchaseOrder(Order order, List <Order_DTL> orderDTLs) { bool success = false; string orderID = ""; try { Order newOrder = new Order(); newOrder.OrderID = GenerateRandomOrderID(); newOrder.supplierID = order.supplierID; success = Handler.newProductOrder(newOrder); if (success != false) { foreach (Order_DTL prod in orderDTLs) { Order_DTL newOrderDL = new Order_DTL(); newOrderDL.OrderID = newOrder.OrderID; newOrderDL.ProductID = prod.ProductID; newOrderDL.Qty = prod.Qty; success = Handler.newProductOrderDL(newOrderDL); } } orderID = newOrder.OrderID; } catch (Exception err) { logAnError("Error making new product order | Error: " + err); return("Err"); } if (success == true) { //email to supplier Supplier supp = Handler.getSupplier(order.supplierID); //send an email notification var body = new System.Text.StringBuilder(); body.AppendFormat("Hello " + supp.contactName.ToString() + ","); body.AppendLine(@""); body.AppendLine(@""); body.AppendLine(@"Please review the purchase order request at the link below"); body.AppendLine(@""); body.AppendLine(@"http://sict-iis.nmmu.ac.za/beauxdebut/Manager/Products.aspx?Action=ViewOrder&OrderID=" + orderID); body.AppendLine(@""); body.AppendLine(@"Regards,"); body.AppendLine(@""); body.AppendLine(@"The Cheveux Team"); sendEmailAlert(supp.contactEmail, supp.contactName, "Purchase Order Request", body.ToString(), "Cheveux"); //show order details to user return(orderID); } else if (success == false) { logAnError("Error making new product order"); return("Err"); } return("Err"); }