Пример #1
0
        public static string CommitInvoice(LocalInvoice newInvoice, bool updateRRP)
        {
            bool isMYOBV7 = CheckIfMYOBV7();

               string statusMesssage = "";

               int staffID = GetLastStaffID();

               int supplierID = GetSupplierID("healthstop_"+newInvoice.supplierID.ToString());

               if (supplierID == 0)
               {
                    throw new Exception("Supplier not found. Check that custom2 for this Supplier has a healthstop ID.");
               }
               else
               {
                    int newGoodsID = GetNewGoodsID();

                    bool useAverageCost = GetCostingMethod();

                    int order_id = String.IsNullOrEmpty(newInvoice.purchaseorder_code) ? 0 : Convert.ToInt32(newInvoice.purchaseorder_code);

                    CreateNewGoodsReceived(newInvoice, newGoodsID, staffID, supplierID, order_id);

                    foreach (var item in newInvoice.itemList)
                    {
                         statusMesssage += CreateNewGoodsReceivedLine(item, supplierID, newGoodsID, isMYOBV7);

                         Stock foundStock = GetStock(item.barcode);

                         CreateAuditEntries(foundStock, item, newGoodsID);

                         UpdateStock(item , useAverageCost,updateRRP, foundStock);
                    }

                    //All items in parent order that are outstanding need to be set as received otherwise when a manual Goods Received is processed for this supplier there will be a whole bunch of previous POs.

                    if (order_id != 0)
                    {
                         UpdateParentPurchaseOrder(order_id, newGoodsID);
                    }
               }
               return statusMesssage;
        }
Пример #2
0
        public OrderResponse DownloadInvoices(int companyID, string password)
        {
            var newResponse = new OrderResponse();

            newResponse.is_error = false;
            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
                    {
                        var invoices = Invoice.GetInvoicesForDownloadByCustomer(currentCompany.company_id);

                        if (invoices.Count == 0)
                        {
                            newResponse.statusMessage = "No invoices to download";
                        }

                        else
                        {
                            newResponse.localInvoices = new List <LocalInvoice>();
                            foreach (var invoice in invoices)
                            {
                                var newInvoice = new LocalInvoice();
                                newInvoice.invoice_id   = invoice.invoice_id;
                                newInvoice.supplierID   = invoice.supplier_id;
                                newInvoice.supplierName = invoice.supplierName;
                                if (String.IsNullOrEmpty(invoice.local_code))
                                {
                                    newInvoice.supplier_code = invoice.invoice_id.ToString();
                                }
                                else
                                {
                                    newInvoice.supplier_code = invoice.local_code;
                                }

                                if (invoice.purchaseorder_ != null)
                                {
                                    newInvoice.purchaseorder_code = invoice.purchaseorder_.local_code;
                                }

                                newInvoice.freight_inc       = invoice.freight;
                                newInvoice.tax               = invoice.tax;
                                newInvoice.total_inc         = invoice.total;
                                newInvoice.creation_datetime = invoice.creation_datetime;

                                var newItemList = new List <LocalInvoiceItem>();

                                foreach (var item in invoice.InvoiceItemsByinvoice_)
                                {
                                    var newItem = new LocalInvoiceItem();

                                    newItem.barcode     = item.barcode;
                                    newItem.quantity    = item.quantity;
                                    newItem.cost_ex     = item.cost_price;
                                    newItem.RRP         = item.RRP;
                                    newItem.isGST       = item.is_GST;
                                    newItem.description = item.description;

                                    newItemList.Add(newItem);
                                }

                                newInvoice.itemList = newItemList;

                                newResponse.localInvoices.Add(newInvoice);
                            }
                            newResponse.statusMessage = newResponse.localInvoices.Count + " Invoices available";
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                newResponse.is_error     = true;
                newResponse.errorMessage = "GenericError";
                LogHelper.WriteError(ex.ToString());
            }
            return(newResponse);
        }
Пример #3
0
        private static void CreateNewGoodsReceived(LocalInvoice newInvoice, int newGoodsID, int staff_id,  int supplier_id, int order_id)
        {
            decimal subtotal_ex = CalculateSubtotalEx(newInvoice);
               decimal subtotal_inc = CalculateSubtotalInc(newInvoice);

               decimal freight_ex = newInvoice.freight_inc / 1.1M;
               decimal total_ex = subtotal_ex + freight_ex;

               string RMDBLocation = Properties.Settings.Default.RMDBLocation;

               try
               {
                    OleDbConnection RMDBconnection = null;

                    RMDBconnection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0; User Id=; Password=; Data Source=" + RMDBLocation);
                    RMDBconnection.Open();

                    OleDbCommand insertCmd = RMDBconnection.CreateCommand();
                    //Get customers.
                    string commandText = @"INSERT INTO Goods (goods_id, goods_date, staff_id, supplier_id,
                                                              invoice_no, invoice_date, order_no, order_id,
                                                              comments, exported, subtotal_ex, subtotal_inc,
                                                              freight_tax, freight_ex, freight_inc, total_inc,
                                                              total_ex, expected)
                                                       VALUES (?,?,?,?,
                                                               ?,?,?,?,
                                                               ?,?,?,?,
                                                               ?,?,?,?,
                                                               ?,?)";

                    insertCmd.CommandText = commandText;
                    insertCmd.Parameters.Add("@goods_id", OleDbType.Integer).Value = newGoodsID;
                    insertCmd.Parameters.Add("@goods_date", OleDbType.Date).Value = DateTime.Now;
                    insertCmd.Parameters.Add("@staff_id", OleDbType.Integer).Value = staff_id;
                    insertCmd.Parameters.Add("@supplier_id", OleDbType.Integer).Value = supplier_id;

                    insertCmd.Parameters.Add("@invoice_no", OleDbType.Integer).Value = newInvoice.supplier_code;
                    insertCmd.Parameters.Add("@invoice_date", OleDbType.Date).Value = newInvoice.creation_datetime;
                    insertCmd.Parameters.Add("@order_no", OleDbType.VarChar).Value = order_id.ToString();
                    insertCmd.Parameters.Add("@order_id", OleDbType.Integer).Value = order_id;

                    insertCmd.Parameters.Add("@comments", OleDbType.VarChar).Value = "Written by Healthstop POS Client";
                    insertCmd.Parameters.Add("@exported", OleDbType.Boolean).Value = false;
                    insertCmd.Parameters.Add("@subtotal_ex", OleDbType.Currency).Value = subtotal_ex;
                    insertCmd.Parameters.Add("@subtotal_inc", OleDbType.Currency).Value = subtotal_inc;

                    insertCmd.Parameters.Add("@freight_tax", OleDbType.VarChar).Value = "GST";
                    insertCmd.Parameters.Add("@freight_ex", OleDbType.Currency).Value = freight_ex;
                    insertCmd.Parameters.Add("@freight_inc", OleDbType.Currency).Value = newInvoice.freight_inc;
                    insertCmd.Parameters.Add("@total_inc", OleDbType.Currency).Value = newInvoice.total_inc;

                    insertCmd.Parameters.Add("@total_ex", OleDbType.Currency).Value = total_ex;
                    insertCmd.Parameters.Add("@expected", OleDbType.Currency).Value = newInvoice.total_inc;

                    insertCmd.ExecuteNonQuery();

                    RMDBconnection.Close();
               }
               catch (Exception ex)
               {
                    throw;
               }
        }
Пример #4
0
 private static decimal CalculateSubtotalInc(LocalInvoice newInvoice)
 {
     return newInvoice.itemList.Sum(i=> i.isGST ? (1.1M* i.cost_ex*(decimal)i.quantity) : i.cost_ex*(decimal)i.quantity);
 }
Пример #5
0
        public OrderResponse DownloadInvoices(int companyID, string password)
        {
            var newResponse = new OrderResponse();
               newResponse.is_error = false;
               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
                         {
                              var invoices = Invoice.GetInvoicesForDownloadByCustomer(currentCompany.company_id);

                              if (invoices.Count == 0)
                              {
                                   newResponse.statusMessage = "No invoices to download";
                              }

                              else
                              {
                                   newResponse.localInvoices = new List<LocalInvoice>();
                                   foreach (var invoice in invoices)
                                   {
                                        var newInvoice = new LocalInvoice();
                                        newInvoice.invoice_id = invoice.invoice_id;
                                        newInvoice.supplierID = invoice.supplier_id;
                                        newInvoice.supplierName = invoice.supplierName;
                                        if (String.IsNullOrEmpty(invoice.local_code))
                                        {
                                             newInvoice.supplier_code = invoice.invoice_id.ToString();
                                        }
                                        else
                                        {
                                             newInvoice.supplier_code = invoice.local_code;
                                        }

                                        if (invoice.purchaseorder_ != null)
                                        {
                                             newInvoice.purchaseorder_code = invoice.purchaseorder_.local_code;
                                        }

                                        newInvoice.freight_inc = invoice.freight;
                                        newInvoice.tax = invoice.tax;
                                        newInvoice.total_inc = invoice.total;
                                        newInvoice.creation_datetime = invoice.creation_datetime;

                                        var newItemList = new List<LocalInvoiceItem>();

                                        foreach (var item in invoice.InvoiceItemsByinvoice_)
                                        {
                                             var newItem = new LocalInvoiceItem();

                                             newItem.barcode = item.barcode;
                                             newItem.quantity = item.quantity;
                                             newItem.cost_ex = item.cost_price;
                                             newItem.RRP = item.RRP;
                                             newItem.isGST = item.is_GST;
                                             newItem.description = item.description;

                                             newItemList.Add(newItem);
                                        }

                                        newInvoice.itemList = newItemList;

                                        newResponse.localInvoices.Add(newInvoice);
                                   }
                                   newResponse.statusMessage = newResponse.localInvoices.Count + " Invoices available";
                              }
                         }
                    }
               }
               catch (Exception ex)
               {
                    newResponse.is_error = true;
                    newResponse.errorMessage = "GenericError";
                    LogHelper.WriteError(ex.ToString());
               }
               return newResponse;
        }