Exemplo n.º 1
0
        protected void AddProductButton_Click(object sender, EventArgs e)
        {
            if (IsValid)
            {
                string barcode  = BarcodeTextBox.Text;
                double quantity = Convert.ToDouble(QuantityTextBox.Text);

                var foundProduct = SupplierProduct.findProductByBarcode(currentOrder.supplier_id, barcode);

                if (foundProduct != null)
                {
                    if (currentOrder.PurchaseOrderItemsBypurchaseorder_.Where(i => i.barcode == barcode).Count() > 0)
                    {
                        AddProductsErrorLabel.Text = "This item is already in the order. Please delete and add again.";
                    }
                    else
                    {
                        PurchaseOrderItem newOrderItem = currentOrder.CreatePurchaseOrderItem();
                        newOrderItem.barcode      = foundProduct.barcode;
                        newOrderItem.cost_price   = foundProduct.CalculateApplicableCost(quantity, permission.is_member);
                        newOrderItem.description  = foundProduct.description;
                        newOrderItem.product_code = foundProduct.product_code;
                        newOrderItem.quantity     = quantity;

                        newOrderItem.Save();
                    }
                    currentOrder.Refresh();
                    PopulateOrderItems();
                }
                else
                {
                    AddProductsErrorLabel.Text = "Product not found";
                }
            }
        }
Exemplo n.º 2
0
        protected void CalculateButton_Click(object sender, EventArgs e)
        {
            if (IsValid)
            {
                string barcode  = BarcodeTextBox.Text;
                double quantity = Convert.ToDouble(QuantityTextBox.Text);

                var foundProduct = SupplierProduct.findProductByBarcode(currentOrder.supplier_id, barcode);


                FinalCostLabel.Text = "$" + foundProduct.CalculateTotalCost(quantity, permission.is_member).ToString("0.00");
            }
        }
Exemplo n.º 3
0
        protected void FindButton_Click(object sender, EventArgs e)
        {
            string barcode = BarcodeTextBox.Text;

            var foundProduct = SupplierProduct.findProductByBarcode(currentOrder.supplier_id, barcode);

            if (foundProduct != null)
            {
                DescriptionLabel.Text = foundProduct.description;
                CostsLabel.Text       = foundProduct.ShowPrices();
                QuantityTextBox.Text  = "";
                FinalCostLabel.Text   = "";
            }
            else
            {
                DescriptionLabel.Text = "Product not found.";
                CostsLabel.Text       = "";
                QuantityTextBox.Text  = "";
                FinalCostLabel.Text   = "";
            }
        }
Exemplo n.º 4
0
        protected void CreateInvoiceImageButton_Command(object sender, CommandEventArgs e)
        {
            ImageButton ib = (ImageButton)sender;
            int         purchaseOrderId = Convert.ToInt32(ib.CommandArgument);

            try
            {
                PurchaseOrder foundOrder = PurchaseOrder.GetPurchaseOrder(purchaseOrderId);
                AllowedStore  permission = AllowedStore.GetAllowedStoreByCustomerSupplier(foundOrder.customer_id, homeCompany.company_id);

                Invoice newInvoice = foundOrder.CreateInvoice();

                newInvoice.customer_id       = foundOrder.customer_id;
                newInvoice.supplier_id       = foundOrder.supplier_id;
                newInvoice.freight           = 10;
                newInvoice.total             = 0;
                newInvoice.creation_datetime = DateTime.UtcNow;

                newInvoice.Save();

                newInvoice.Refresh();

                foreach (var item in foundOrder.PurchaseOrderItemsBypurchaseorder_)
                {
                    string barcode  = item.barcode;
                    double quantity = item.quantity;

                    var foundProduct = SupplierProduct.findProductByBarcode(homeCompany.company_id, barcode);

                    if (foundProduct != null)
                    {
                        InvoiceItem newItem = newInvoice.CreateInvoiceItem();
                        newItem.barcode      = foundProduct.barcode;
                        newItem.cost_price   = foundProduct.CalculateApplicableCost(quantity, permission.is_member);
                        newItem.description  = foundProduct.description;
                        newItem.product_code = foundProduct.product_code;
                        newItem.quantity     = quantity;
                        newItem.is_GST       = foundProduct.is_GST;
                        newItem.RRP          = foundProduct.RRP;
                        newItem.Save();
                    }
                }

                newInvoice.total = newInvoice.InvoiceItemsByinvoice_.Sum(i => i.subTotal) + newInvoice.freight;
                newInvoice.tax   = newInvoice.InvoiceItemsByinvoice_.Sum(i => i.taxAmount);

                if (!newInvoice.customer_.has_POSSystem)
                {
                    newInvoice.is_downloaded       = true;
                    newInvoice.downloaded_datetime = newInvoice.creation_datetime;
                }
                else
                {
                    newInvoice.is_downloaded = false;
                }

                newInvoice.Save();
                newInvoice.Refresh();

                EmailHelper.SendInvoice(newInvoice);


                PopulateOrderLists();
            }
            catch
            {
                throw;
            }
        }
Exemplo n.º 5
0
        public OrderResponse UploadPurchaseOrders(int companyID, string password, List <LocalPurchaseOrder> orders)
        {
            var newResponse = new OrderResponse();

            newResponse.is_error      = false;
            newResponse.errorMessage  = "";
            newResponse.statusMessage = "";
            try
            {
                Company currentCompany = Company.GetCompany(companyID);

                if (currentCompany == null)
                {
                    newResponse.is_error     = true;
                    newResponse.errorMessage = "NoCompany";
                }
                else
                {
                    if (password != currentCompany.api_key)
                    {
                        newResponse.is_error     = true;
                        newResponse.errorMessage = "IncorrectPassword";
                    }
                    else
                    {
                        foreach (var order in orders)
                        {
                            //Check for duplicate barcodes.
                            List <string> duplicateBarcodes = order.itemList.GroupBy(i => i.barcode)
                                                              .Where(g => g.Count() > 1)
                                                              .Select(g => g.Key)
                                                              .ToList();
                            if (duplicateBarcodes.Count > 0)
                            {
                                string barcodes = String.Join("\r\n", duplicateBarcodes.ToArray());
                                newResponse.is_error      = true;
                                newResponse.errorMessage += "Error with Purchase Order: " + order.local_code + ". Duplicate barcodes: \r\n " + barcodes;
                            }
                            else
                            {
                                var supplier = Company.GetCompany(order.supplier_id);
                                if (supplier == null)
                                {
                                    newResponse.is_error      = true;
                                    newResponse.errorMessage += "Error with Purchase Order: " + order.local_code + ". Supplier not found\r\n";
                                }
                                else
                                {
                                    var permission = AllowedStore.GetAllowedStoreByCustomerSupplier(currentCompany.company_id, supplier.company_id);
                                    if (permission == null)
                                    {
                                        newResponse.is_error      = true;
                                        newResponse.errorMessage += "Error with Purchase Order: " + order.local_code + ". You don't have an account with this supplier.\r\n";
                                    }
                                    else
                                    {
                                        if (PurchaseOrder.GetPurchaseOrdersByCustomerLocalCode(companyID, order.local_code).Count > 0)
                                        {
                                            newResponse.is_error      = true;
                                            newResponse.errorMessage += "Purchase order: " + order.local_code + " to " + supplier.name + " already submitted.\r\n";
                                        }
                                        else
                                        {
                                            PurchaseOrder newOrder = PurchaseOrder.CreatePurchaseOrder();
                                            newOrder.local_code        = order.local_code;
                                            newOrder.customer_id       = currentCompany.company_id;
                                            newOrder.supplier_id       = supplier.company_id;
                                            newOrder.person            = "HealthStop POS Client";
                                            newOrder.creation_datetime = order.order_datetime;


                                            newOrder.Save();
                                            newOrder.Refresh();

                                            foreach (var item in order.itemList)
                                            {
                                                var foundSupplierProduct = SupplierProduct.findProductByBarcode(supplier.company_id, item.barcode);

                                                if (foundSupplierProduct == null)
                                                {
                                                    newResponse.is_error      = true;
                                                    newResponse.errorMessage += "Error with Purchase Order: " + order.local_code + "\r\nProduct not found in supplier list : " + item.barcode + "\r\nOrder submitted without this product." + "\r\n";
                                                }
                                                else
                                                {
                                                    var newItem = PurchaseOrderItem.CreatePurchaseOrderItem();
                                                    newItem.purchaseorder_id = newOrder.purchaseorder_id;
                                                    newItem.product_code     = foundSupplierProduct.product_code;
                                                    newItem.barcode          = foundSupplierProduct.barcode;
                                                    newItem.description      = foundSupplierProduct.description;
                                                    newItem.cost_price       = foundSupplierProduct.CalculateApplicableCost(item.quantity, permission.is_member);
                                                    newItem.quantity         = item.quantity;

                                                    newItem.Save();
                                                }
                                            }

                                            newOrder.Refresh();
                                            if (newOrder.PurchaseOrderItemsBypurchaseorder_.Count == 0)
                                            {
                                                newResponse.is_error      = true;
                                                newResponse.errorMessage += "Error with Purchase Order: " + order.local_code + " No items to order" + "\r\n";
                                                newOrder.Delete();
                                            }
                                            else
                                            {
                                                EmailHelper.SendXMLOrder("HealthStop Auto", currentCompany, supplier, newOrder.createEDI());
                                                newOrder.submitted_datetime = DateTime.UtcNow;
                                                newOrder.is_submitted       = true;
                                                newOrder.Save();

                                                newResponse.statusMessage += "Purchase Order: " + order.local_code + ". sent successfully to " + supplier.name + "\r\n";
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                newResponse.is_error     = true;
                newResponse.errorMessage = "GenericError";
                LogHelper.WriteError(ex.ToString());
            }
            return(newResponse);
        }